Registry / devops / rollup-plugin-dynamic-import-variables

rollup-plugin-dynamic-import-variables

JSON →
library1.1.0jsnpmunverified

Rollup plugin (v1.1.0) that resolves dynamic imports containing variables at build time by converting concatenated strings into glob patterns and bundling matching files. Maintained by LarsDenBakker with infrequent releases. Key differentiator: enables dynamic imports with variable parts in Rollup, similar to webpack's dynamic import handling, without requiring complex configuration. Supports ESM and CJS. Alternatives include @rollup/plugin-dynamic-import-vars (official fork) which is more actively maintained.

npm install rollup-plugin-dynamic-import-variables
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-DYNA
R
rollup-plugin-dynamic-import-variables
devopsjavascriptv1.1.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default (dynamicImportVariables)
import dynamicImportVariables from 'rollup-plugin-dynamic-import-variables';
const dynamicImportVariables = require('rollup-plugin-dynamic-import-variables');
CommonJS require works but ESM import is recommended for consistency with Rollup config.
dynamicImportVariables
import dynamicImportVariables from 'rollup-plugin-dynamic-import-variables';
import * as dynamicImportVariables from 'rollup-plugin-dynamic-import-variables';
The default export is used directly; namespace import is incorrect.
dynamicImportVariables (as function call)
export default { plugins: [ dynamicImportVariables({ include: ['**/*.js'] }) ] }
export default { plugins: [ new dynamicImportVariables() ] }
It's a factory function, not a class; do not use 'new'.

Configures Rollup to resolve dynamic imports with variables (e.g., `import('./locales/' + locale + '.js')`) by bundling matching files.

// rollup.config.js import dynamicImportVariables from 'rollup-plugin-dynamic-import-variables'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'esm' }, plugins: [ dynamicImportVariables({ // Only process files in 'src' folder include: ['src/**'], // Exclude node_modules by default exclude: ['node_modules/**'], // Warn instead of error for problematic imports warnOnError: true }) ] };
Debug
Known issues
breakingDynamic imports must start with './' or '../' - variable-only paths are not supported.
fix
Prefix the dynamic import with a relative path, e.g., `import('./' + name + '.js')` instead of `import(name)`.
affects: all
breakingDynamic imports must end with a file extension in the static part.
fix
Ensure the import string ends with a file extension (e.g., `.js`, `.mjs`). For example: `import('./' + name + '.js')`.
affects: all
gotchaGlobs only go one level deep per directory - nested variables may not import as expected.
fix
Avoid multiple variables in the same directory segment; reorganize directory structure if deeper recursion is needed.
affects: all
gotchaImporting your own directory (e.g., `import('./' + name + '.js')`) is not allowed if the import path resolves to the same directory as the source file.
fix
Use a more specific filename pattern, e.g., `import('./module-' + name + '.js')`.
affects: all
deprecatedThis package is no longer actively maintained; consider using the official fork '@rollup/plugin-dynamic-import-vars'.
fix
Replace 'rollup-plugin-dynamic-import-variables' with '@rollup/plugin-dynamic-import-vars' in your dependencies and import.
affects: >=1.1.0
Errors
Common errors & fixes
Error: Could not resolve './foo/bar.js' from 'src/index.js'
The glob pattern matched files but the exact import path is not found because the file doesn't exist or the pattern is too restrictive.
fix
Check that the variable parts produce at least one valid file path. Adjust the import pattern or ensure the referenced files exist.
(!) Plugin dynamic-import-variables: Dynamic imports must start with './' or '../'
The dynamic import string starts with a variable or bare module specifier (e.g., `import(bar)` or `import("some-library/" + bar + ".js")`).
fix
Prefix the import with a relative path starting with './' or '../'.
(!) Plugin dynamic-import-variables: Dynamic imports must end with a file extension
The dynamic import string does not contain a file extension in the static part (e.g., `import('./' + name)` without '.js').
fix
Add a file extension to the static part of the import string, e.g., `import('./' + name + '.js')`.
(!) Plugin dynamic-import-variables: Imports to your own directory must specify a filename pattern
The import matches the same directory as the source file without specifying a filename pattern (e.g., `import('./' + name + '.js')` when in the same directory).
fix
Add a static prefix or suffix to the filename part, e.g., `import('./module-' + name + '.js')`.
Upgrade
Version history
1.1.0latest on npm
Audit
Dependencies
@rollup/pluginutilsrequiredProvides utility functions for plugin development (e.g., filtering, id resolution)
@rollup/plugin-node-resolveoptionalReplaces native node resolve for compatibility (if using CommonJS modules)
Agent activity
9 hits · last 30 days
node
8
Resources
rollup-plugin-dynamic-import-variables — npm install rollup-plugin-dynamic-import-variables · libregistry