Vite "[vite:dynamic-import-vars] ... cannot be analyzed" in CI
Vite statically analyzes import() calls with variables so it can split them into chunks. When the expression is too open (a bare variable, or a path that escapes a fixed prefix), Vite cannot enumerate the targets and fails the build.
What this error means
The build fails with "[plugin vite:dynamic-import-vars] ... cannot be analyzed by the dynamic import bundler. Please add the @vite-ignore comment to disable this optimization."
error during build:
[plugin vite:dynamic-import-vars] src/loader.ts: The above dynamic import cannot
be analyzed by Vite.
See https://github.com/rollup/plugins/tree/master/packages/dynamic-import-vars#limitations
for supported dynamic import formats. If this is intended to be left as-is, you can
use the /* @vite-ignore */ comment inside the import() call to disable this error.Common causes
A fully variable import path
An import(path) where path is a bare variable gives Vite no fixed prefix or pattern to enumerate, so it cannot build the chunk map.
A path that escapes its directory
Templates that allow ../ or no leading ./ defeat the analyzer's constraints on supported dynamic import formats.
How to fix it
Constrain the dynamic import to a pattern
- Give the import a literal prefix and suffix so Vite can glob the matches.
- Keep the variable part to a single path segment with no
../. - Re-run the build so the analyzer can enumerate targets.
// analyzable: fixed prefix, fixed extension
const mod = await import(`./locales/${lang}.js`);Opt out with @vite-ignore when intended
If the import must stay fully dynamic and you accept no code splitting for it, disable the optimization explicitly.
const mod = await import(/* @vite-ignore */ path);How to prevent it
- Give dynamic imports a literal prefix and extension.
- Avoid
../and bare variables insideimport()paths. - Use
@vite-ignoreonly when a fully dynamic import is intentional.