Vite "dynamic import will not be analyzed" warning to error in CI
Vite analyzes import() calls statically to generate chunks. When the imported path is a fully dynamic variable with no static prefix, Vite cannot determine which files to emit and warns that the import will not be analyzed.
What this error means
vite build prints "The above dynamic import cannot be analyzed by Vite. See ... for supported dynamic import formats. If this is intended to be left as-is, you can use the /* @vite-ignore */ comment", and the lazy module 404s at runtime in CI.
src/router.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.Common causes
A fully variable import path
An import(someVariable) with no static portion gives Vite nothing to glob, so it cannot pre-create the chunk.
A path that escapes the project root
Dynamic import paths that start outside the project (../../) or are absolute fall outside what the analyzer supports.
How to fix it
Add a static prefix and suffix to the import
Give the dynamic import a literal directory and extension so Vite can glob the candidates.
// analyzable: literal start + extension
const mod = await import(`./pages/${name}.ts`)Opt out explicitly when the import is external
If the path is intentionally runtime-only, silence the analyzer so it is left as-is.
const mod = await import(/* @vite-ignore */ url)How to prevent it
- Keep a static literal prefix and extension in dynamic imports.
- Avoid dynamic import paths that leave the project root.
- Use
/* @vite-ignore */only for genuinely external runtime imports.