Skip to content
Latchkey

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.

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

src/router.ts
// 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.

src/loader.ts
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.

Frequently asked questions

What causes ""dynamic import will not be analyzed""?
An import(someVariable) with no static portion gives Vite nothing to glob, so it cannot pre-create the chunk.
How do I fix "dynamic import will not be analyzed"?
Give the dynamic import a literal directory and extension so Vite can glob the candidates.

Related guides

References

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