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.
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.
export default {
build: { target: 'es2022' }
}Set the esbuild target for both passes
Align the optimizeDeps/esbuild target so dependency pre-bundling also allows it.
export default {
build: { target: 'esnext' },
optimizeDeps: { esbuildOptions: { target: 'esnext' } }
}How to prevent it
- Set an explicit
build.targetof 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.