Skip to content
Latchkey

Vite "Top-level await is not available in the configured target" in CI

esbuild (used by Vite) refuses to emit top-level await when the configured build.target predates ES2022. The feature is real in your source, but the chosen output target cannot express it.

What this error means

vite build fails with "Top-level await is not available in the configured target environment (\"es2019\", ...)" pointing at a module that awaits at the top level.

vite
error during build:
Top-level await is not available in the configured target environment
("chrome87", "edge88", "es2019", "firefox78", "safari14") (1:0)

Common causes

The build target is older than ES2022

Top-level await landed in ES2022. A build.target such as es2019 or a legacy browserslist makes esbuild reject it.

A dependency uses top-level await

A package in the graph awaits at module scope, so even if your code does not, the configured target still blocks the build.

How to fix it

Raise the build target

Set a target that supports top-level await so esbuild can emit it.

vite.config.js
export default {
  build: { target: 'es2022' }
}

Set the esbuild target for both passes

Align the optimizeDeps/esbuild target so dependency pre-bundling also allows it.

vite.config.js
export default {
  build: { target: 'esnext' },
  optimizeDeps: { esbuildOptions: { target: 'esnext' } }
}

How to prevent it

  • Set an explicit build.target of ES2022 or newer when using top-level await.
  • Keep browserslist and Vite target consistent.
  • Check whether new dependencies use top-level await before pinning an old target.

Frequently asked questions

What causes ""Top-level await is not available""?
Top-level await landed in ES2022. A build.target such as es2019 or a legacy browserslist makes esbuild reject it.
How do I fix "Top-level await is not available"?
Set a target that supports top-level await so esbuild can emit it.

Related guides

References

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