Skip to content
Latchkey

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."

vite
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

  1. Give the import a literal prefix and suffix so Vite can glob the matches.
  2. Keep the variable part to a single path segment with no ../.
  3. Re-run the build so the analyzer can enumerate targets.
src/loader.ts
// 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.

src/loader.ts
const mod = await import(/* @vite-ignore */ path);

How to prevent it

  • Give dynamic imports a literal prefix and extension.
  • Avoid ../ and bare variables inside import() paths.
  • Use @vite-ignore only when a fully dynamic import is intentional.

Frequently asked questions

What causes ""dynamic-import-vars ... cannot be analyzed""?
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.
How do I fix "dynamic-import-vars ... cannot be analyzed"?
Constrain the dynamic import to a pattern

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card