Skip to content
Latchkey

Vite "[vite]: Build failed with errors" - Diagnose the Real Cause

"Build failed with errors" is Vite's umbrella message; the real failure - a parse error, an unresolved import, or a plugin throwing - is in the lines around it. Read those, not the summary.

What this error means

vite build ends with [vite]: Build failed with errors and a non-zero exit, with one or more specific errors printed just above (Rollup resolve failure, esbuild transform error, or a plugin error).

vite
vite v5.2.0 building for production...
✗ 42 modules transformed.
src/pages/Home.tsx (12:8): ERROR: Expected ">" but found "className"
[vite]: Build failed with errors.
error during build:

Diagnose it: is it resolution, transform, or memory?

Bundler failures in CI fall into three families and the error text often points at the wrong one. A module that resolves on your machine and not on the runner is nearly always case sensitivity or a missing optional dependency; a transform error is a config or version mismatch; and an unexplained kill with no stack is the out-of-memory reaper, not a build error at all.

Terminal
# 1. resolution: does the file exist with EXACTLY that case?
git ls-files | grep -i "the/imported/path"

# 2. transform: what versions is CI actually resolving?
npm ls webpack vite rollup esbuild typescript 2>/dev/null | head -20

# 3. memory: was it killed rather than failed?
#    exit 137 = SIGKILL (OOM). Nothing in the bundler log will explain it.
node --max-old-space-size=4096 node_modules/.bin/vite build

Common causes

A transform or syntax error in a module

esbuild (Vite's transformer) hit invalid syntax or JSX in a .ts file. The umbrella message hides the specific file/line printed above it.

An unresolved import or failing plugin

A Rollup resolve failure or a plugin throwing during the build rolls up into the generic "Build failed" line.

How to fix it

Read the specific error above the summary

  1. Scroll up from "Build failed with errors" to the first ✗/ERROR line - it names the file, line, and real cause.
  2. Fix that underlying error (syntax, import, or plugin) rather than the summary.
  3. Re-run vite build locally to confirm the specific error is gone.

Reproduce with full logs

Run the build verbosely so the underlying error is not truncated in CI output.

Terminal
vite build --debug
# or temporarily: DEBUG=vite:* vite build

Make the build reproducible before you debug it

  • Pin the Node major in setup-node and in engines. A bundler that resolves native bindings will pick a different prebuilt binary across majors.
  • Delete node_modules locally and reinstall from the lockfile before concluding the runner is at fault; most "works locally" reports are stale local state.
  • Set CI=true locally to reproduce. Several toolchains change behaviour under it, including treating warnings as errors.
  • Exit code 137 is an out-of-memory kill. Raise --max-old-space-size or move to a larger runner rather than searching the bundler config.

How to prevent it

  • Run vite build in CI so production-only failures surface before deploy.
  • Keep JSX in .tsx/.jsx so the esbuild transform picks the right loader.
  • Treat the umbrella message as a pointer - always read the specific error above it.

Frequently asked questions

What causes Vite "[vite]: build failed with errors"?
There are 2 common causes: a transform or syntax error in a module and an unresolved import or failing plugin. esbuild (Vite's transformer) hit invalid syntax or JSX in a .ts file.
How do I fix Vite "[vite]: build failed with errors"?
There are 2 fixes depending on which cause you have: read the specific error above the summary and reproduce with full logs. Work through them in order, since the first is the most common.
What does Vite "[vite]: build failed with errors" actually mean?
vite build ends with [vite]: Build failed with errors and a non-zero exit, with one or more specific errors printed just above (Rollup resolve failure, esbuild transform error, or a plugin error).
How do I stop Vite "[vite]: build failed with errors" happening again?
Run vite build in CI so production-only failures surface before deploy. The prevention section lists 3 changes that keep it from recurring.

Related guides

References

Not every red build is your code. Latchkey repairs the ones that are not, on the runner. Start free → 30-day trial · No credit card