{"id":21996,"library":"rollup-plugin-dynamic-import-variables","title":"rollup-plugin-dynamic-import-variables","description":"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.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/LarsDenBakker/rollup-plugin-dynamic-import-variables","tags":["javascript"],"install":[{"cmd":"npm install rollup-plugin-dynamic-import-variables","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-dynamic-import-variables","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-dynamic-import-variables","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Provides utility functions for plugin development (e.g., filtering, id resolution)","package":"@rollup/pluginutils","optional":false},{"reason":"Replaces native node resolve for compatibility (if using CommonJS modules)","package":"@rollup/plugin-node-resolve","optional":true}],"imports":[{"note":"CommonJS require works but ESM import is recommended for consistency with Rollup config.","wrong":"const dynamicImportVariables = require('rollup-plugin-dynamic-import-variables');","symbol":"default (dynamicImportVariables)","correct":"import dynamicImportVariables from 'rollup-plugin-dynamic-import-variables';"},{"note":"The default export is used directly; namespace import is incorrect.","wrong":"import * as dynamicImportVariables from 'rollup-plugin-dynamic-import-variables';","symbol":"dynamicImportVariables","correct":"import dynamicImportVariables from 'rollup-plugin-dynamic-import-variables';"},{"note":"It's a factory function, not a class; do not use 'new'.","wrong":"export default { plugins: [ new dynamicImportVariables() ] }","symbol":"dynamicImportVariables (as function call)","correct":"export default { plugins: [ dynamicImportVariables({ include: ['**/*.js'] }) ] }"}],"quickstart":{"code":"// rollup.config.js\nimport dynamicImportVariables from 'rollup-plugin-dynamic-import-variables';\n\nexport default {\n  input: 'src/index.js',\n  output: { dir: 'dist', format: 'esm' },\n  plugins: [\n    dynamicImportVariables({\n      // Only process files in 'src' folder\n      include: ['src/**'],\n      // Exclude node_modules by default\n      exclude: ['node_modules/**'],\n      // Warn instead of error for problematic imports\n      warnOnError: true\n    })\n  ]\n};","lang":"javascript","description":"Configures Rollup to resolve dynamic imports with variables (e.g., `import('./locales/' + locale + '.js')`) by bundling matching files."},"warnings":[{"fix":"Prefix the dynamic import with a relative path, e.g., `import('./' + name + '.js')` instead of `import(name)`.","message":"Dynamic imports must start with './' or '../' - variable-only paths are not supported.","severity":"breaking","affected_versions":"all"},{"fix":"Ensure the import string ends with a file extension (e.g., `.js`, `.mjs`). For example: `import('./' + name + '.js')`.","message":"Dynamic imports must end with a file extension in the static part.","severity":"breaking","affected_versions":"all"},{"fix":"Avoid multiple variables in the same directory segment; reorganize directory structure if deeper recursion is needed.","message":"Globs only go one level deep per directory - nested variables may not import as expected.","severity":"gotcha","affected_versions":"all"},{"fix":"Use a more specific filename pattern, e.g., `import('./module-' + name + '.js')`.","message":"Importing your own directory (e.g., `import('./' + name + '.js')`) is not allowed if the import path resolves to the same directory as the source file.","severity":"gotcha","affected_versions":"all"},{"fix":"Replace 'rollup-plugin-dynamic-import-variables' with '@rollup/plugin-dynamic-import-vars' in your dependencies and import.","message":"This package is no longer actively maintained; consider using the official fork '@rollup/plugin-dynamic-import-vars'.","severity":"deprecated","affected_versions":">=1.1.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Check that the variable parts produce at least one valid file path. Adjust the import pattern or ensure the referenced files exist.","cause":"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.","error":"Error: Could not resolve './foo/bar.js' from 'src/index.js'"},{"fix":"Prefix the import with a relative path starting with './' or '../'.","cause":"The dynamic import string starts with a variable or bare module specifier (e.g., `import(bar)` or `import(\"some-library/\" + bar + \".js\")`).","error":"(!) Plugin dynamic-import-variables: Dynamic imports must start with './' or '../'"},{"fix":"Add a file extension to the static part of the import string, e.g., `import('./' + name + '.js')`.","cause":"The dynamic import string does not contain a file extension in the static part (e.g., `import('./' + name)` without '.js').","error":"(!) Plugin dynamic-import-variables: Dynamic imports must end with a file extension"},{"fix":"Add a static prefix or suffix to the filename part, e.g., `import('./module-' + name + '.js')`.","cause":"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).","error":"(!) Plugin dynamic-import-variables: Imports to your own directory must specify a filename pattern"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}