Welcome to HowToShipIt — practical how-to guides for developers: code, AI tools, and servers, explained step by step.

How to Fix Vite Build Errors: 9 Causes and Copy-Paste Fixes (2026)

Vite build errors are the worst kind of red in your terminal: the dev server works fine, your code looks fine, and then npm run build stops dead. The fix is almost never “delete node_modules and pray” — it is reading the first three lines of the error properly, because Vite 8 tells you exactly what broke. This guide covers the nine vite build errors you will actually hit, with the exact message, the cause, and a copy-paste fix for each. Everything here was verified against the Vite 8 documentation and reproduced error output on 25 November 2026.

One thing to know before you start: Vite 8, released 12 March 2026, replaced both esbuild and Rollup with a single Rust bundler, Rolldown, and Oxc for transforms. That means the error messages you see today are Rolldown messages, not Rollup ones — [vite]: Rolldown failed to resolve import instead of the old [vite]: Rollup failed to resolve import. The fixes are the same; only the names changed. Vite 8 needs Node.js 20.19+ or 22.12+, so check your Node version first if anything below looks unfamiliar: node -v.

Before you fix anything: read the error properly

A Vite build failure has three parts, and most people only read the last one:

  • The error code in brackets, for example [UNRESOLVED_IMPORT]. It tells you the category before you read a word of the message.
  • The message itself, which names the module and the file that imported it. That is the whole diagnosis in one line.
  • The code frame, the little snippet with a caret pointing at the exact line and column. If the message names a file you did not write, the frame tells you which of your files pulled it in.

Run the build with verbose output before you change anything:

vite build --debug

The debug output shows the exact file, loader, or plugin that failed instead of the summary. And never start by deleting node_modules: it wastes minutes, it hides the real cause, and on a CI machine it changes nothing about the error. Read first, fix second.

1. [vite]: Rolldown failed to resolve import

The error:

Error: [vite]: Rolldown failed to resolve import "lodash-es" from "/work/app/src/main.js".
This is most likely unintended because it can break your application at runtime.
If you do want to externalize this module explicitly add it to
`build.rolldownOptions.external`

What it means: the bundler followed a bare import — a package name, not a relative path — and found nothing in node_modules. The external hint at the end is a trap: it is only relevant if the module is deliberately loaded from outside the bundle, for example a CDN global. Do not add external first.

The fix: check whether the package is actually installed where the build runs.

npm ls lodash-es
npm install lodash-es

If npm ls prints nothing, the package is missing from package.json — add it. The classic version of this bug is a package that only exists in devDependencies while your CI installs with NODE_ENV=production or --omit=dev, which skips dev dependencies. Either move the package to dependencies or make the build install dev dependencies too (npm install --production=false).

The sneakier version: it builds on your laptop and fails in CI. npm hoists transitive dependencies to the top level, so your code can import a package you never declared and your local install still finds it. pnpm does not hoist by default, so a clean CI install fails immediately. The rule is simple: if your source imports it, it belongs in your own package.json.

2. [UNRESOLVED_IMPORT] Could not resolve ‘./…’

The error:

[UNRESOLVED_IMPORT] Could not resolve './greeter.js' in src/main.js
   ╭─[ src/main.js:1:23 ]

What it means: a relative import points at a file that does not exist at that path. This is the most common of all vite build errors, and it is almost always one of three things: a typo in the file name, a case mismatch, or a missing alias.

The fix: work through the list in order.

  1. Typo: the file is greeting.js and you imported greeter.js. The code frame points at the exact column, so compare the import string character by character.
  2. Case: you imported ./Greeting.js but the file is greeting.js. This passes on macOS and Windows, whose file systems are case-insensitive, and fails on Linux and in CI, which are case-sensitive. Rename the file or the import so they match exactly.
  3. Alias: you imported @/components/Button but Vite does not know what @ means. An alias must resolve to an absolute path:
import { fileURLToPath, URL } from 'node:url'
import { defineConfig } from 'vite'

export default defineConfig({
  resolve: {
    alias: { '@': fileURLToPath(new URL('./src', import.meta.url)) },
  },
})

A relative alias value is used as written and never resolved to a file system path, so the fileURLToPath wrapper is the part people forget.

3. “X does not provide an export named ‘Y'”

The error:

"lodash" does not provide an export named "debounce"

What it means: you used a named ESM import against a package that only ships CommonJS. The package uses module.exports, so there are no named exports for Rolldown to find. This one often appears only in the production build, because the dev server and the build handle CommonJS interop through different paths.

The fix: import the default export and destructure from it:

// ❌ Fails against a CJS-only package
import { debounce } from 'lodash'

// ✅ Works: default import, then destructure
import lodash from 'lodash'
const { debounce } = lodash

Or use the ESM build of the package if it ships one — lodash-es exists precisely for this. If the problem package is a linked monorepo dependency, add it to optimizeDeps.include so Vite pre-bundles it; Vite skips pre-bundling linked dependencies by default because it assumes they are ESM source code.

4. Some chunks are larger than 500 KiB

The error:

Warning: Some chunks are larger than 500 KiB after minification.

What it means: one output chunk is over Vite’s default warning limit of 500 kB (uncompressed, set by build.chunkSizeWarningLimit). This is a warning, not a failure — the build still succeeds — but do not ignore it: large chunks mean slower first loads, because the browser has to download and parse the whole chunk before anything renders.

The fix: split the chunk. The usual culprit is a huge dependency imported statically at the top of your entry file. Load it lazily instead:

// ❌ Bundled into the main chunk
import { Chart } from 'heavy-chart-library'

// ✅ Loaded on demand, in its own chunk
const { Chart } = await import('heavy-chart-library')

For routes, use the same pattern with your framework’s lazy loading — React.lazy, Vue’s defineAsyncComponent, or SvelteKit’s dynamic route imports. If you need explicit control over how chunks are split in Vite 8, use Rolldown’s code splitting option:

export default defineConfig({
  build: {
    rolldownOptions: {
      output: {
        codeSplitting: {
          groups: [
            { name: 'vendor', test: /node_modules/ },
          ],
        },
      },
    },
  },
})

Raising build.chunkSizeWarningLimit is legitimate when the chunk genuinely cannot be split — a single large library with no lazy-load point, for example — but treat it as a last resort, not a first one. Silencing the warning does not make the bundle smaller.

5. CSS minification error

The error:

error during build:
[vite:css] CSS minification error

What it means: Vite 8 minifies CSS with Lightning CSS by default, and Lightning CSS cannot parse something in your stylesheet — usually invalid CSS syntax, a malformed custom property, or a browser hack it does not understand. The build stops because the minifier cannot produce output it trusts.

The fix: find the offending rule first. The error names the file; comment out recent additions in halves until the build passes, then fix the syntax. If the CSS is valid but Lightning CSS still chokes on it, fall back to esbuild for CSS minification only:

npm add -D esbuild
export default defineConfig({
  build: {
    cssMinify: 'esbuild',
  },
})

Note that esbuild is no longer bundled with Vite 8, so you have to install it yourself before setting cssMinify: 'esbuild'. Keep the fallback in place only until you find the real syntax problem — switching minifiers to dodge a parse error is how broken CSS ships to production.

6. Unexpected token: your code is too modern for your target

The error:

error during build:
Unexpected token (123:45)

What it means: the bundle contains syntax that cannot be transpiled down to your build.target. Vite 8 defaults to 'baseline-widely-available' — Chrome 111, Edge 111, Firefox 114, Safari 16.4 — and Oxc warns when code contains features it cannot safely transpile to that range. The usual triggers are a dependency that ships untranspiled modern syntax, or your own code using a feature newer than the target.

The fix: first check whether the syntax comes from a dependency. If it does, that dependency probably needs to be transpiled or replaced — check its package.json for the exports field and whether it ships an older build. If the syntax is yours, lower the target explicitly:

export default defineConfig({
  build: {
    target: 'es2020',
  },
})

The lowest target Vite accepts is es2015. If you genuinely need to support browsers older than the default range, use @vitejs/plugin-legacy, which generates legacy chunks with polyfills that load only in browsers without native ESM support. Do not lower the target for your whole app because one dependency ships modern syntax — that punishes every user for one package’s choice.

7. JavaScript heap out of memory

The error:

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

What it means: the build process ran out of memory. Big apps with thousands of modules, large source maps, or heavy plugins are the usual cause, and it hits hardest in CI, where the container often has far less RAM than your laptop.

The fix: raise Node’s heap limit for the build command:

NODE_OPTIONS="--max-old-space-size=8192" npm run build

Or set it in package.json so CI gets it too:

"scripts": {
  "build": "NODE_OPTIONS=--max-old-space-size=8192 vite build"
}

Two cheaper wins first: disable gzip size reporting with build.reportCompressedSize: false (compressing large outputs to print sizes is slow and memory-hungry), and turn off source maps for production builds unless you actually read them — build.sourcemap defaults to false, so if your config sets it to true, that is memory you can reclaim. If the build still runs out of memory after that, the problem is usually one plugin doing something pathological — run with --debug and watch which step the memory climbs on.

8. Cannot find module ‘@rolldown/binding-…’

The error:

Error: Cannot find module '@rolldown/binding-linux-x64-gnu'

What it means: Rolldown ships platform-specific native binaries, and the one installed does not match the machine running the build. This happens when you install dependencies on one operating system or CPU architecture and build on another — a macOS laptop and a Linux CI runner, an Intel machine and an ARM one, or a Docker image built on a different base.

The fix: reinstall on the target platform. Delete the lockfile and node_modules, then install fresh where the build actually runs:

rm -rf node_modules package-lock.json
npm install

Never copy node_modules between machines or into a Docker image from your host — install inside the image. And do not commit a lockfile generated on a different platform and expect the optional native dependency to follow; the lockfile records the binary for the platform that generated it.

9. Your config won’t load at all

The error:

error when starting dev server:
Error: Expected identifier but found "import"
(define name):1:0

What it means: Vite cannot even load vite.config.js, so nothing else runs. The classic case is a version mismatch: Vite 6.0.0 to 6.0.4 accept any esbuild in the ^0.24.0 range, and esbuild 0.24.1 introduced a regression that rejects define keys starting with import — exactly the keys Vite passes when bundling your config file. The esbuild changelog for 0.24.2 describes it plainly: the 0.24.1 change to the define parser “removed the ability to use --define:import.meta=...“, and 0.24.2 fixes the regression.

The fix:

npm update esbuild
npm install -D vite@latest

Update esbuild to the fixed release, then move to the newest Vite 6 release, which depends on a newer esbuild line. The same “config won’t load” symptom has a second, quieter cause in Vite 8: build.rollupOptions is deprecated in favour of build.rolldownOptions. The old key still works as an alias for now, but rename it — a future major will remove it, and a config that silently relies on a deprecated alias is a build failure waiting for an upgrade day.

It builds on your laptop but fails in CI

If the build passes locally and fails in CI, the error is almost never in your code. Run through this list before touching a source file:

  • Node version: Vite 8 needs Node 20.19+ or 22.12+. Check what CI actually runs — node -v in the CI log — not what your laptop runs.
  • Lockfile drift: if CI installs with --frozen-lockfile (pnpm) or npm ci and the lockfile is stale, the install itself is the failure. Regenerate it locally and commit it.
  • Case sensitivity: macOS lets ./Greeting.js resolve to greeting.js; Linux does not. See error 2.
  • Missing dev dependencies: NODE_ENV=production or --omit=dev skips them. See error 1.
  • Environment variables: Vite only exposes variables prefixed with VITE_ to client code. A build that expects VITE_API_URL fails silently when the variable is missing — check your CI secrets before debugging the code.
  • Stale cache: Vite caches pre-bundled dependencies in node_modules/.vite. If you changed a dependency or a patch and the build behaves strangely, clear it with vite --force or delete the folder.

Your deploy works, then users get vite:preloadError

This one is not a build error, but it is the error your users see because of a build decision. Vite emits a vite:preloadError event when a dynamic import fails to load — most often after a new deployment, when the hosting service has deleted the old chunks and a user with the old page open tries to load one. Handle it in your app:

window.addEventListener('vite:preloadError', (event) => {
  window.location.reload() // load the fresh deployment
})

And set Cache-Control: no-cache on your HTML file, otherwise the browser keeps serving the old page that references the deleted chunks. The assets themselves can stay aggressively cached — only the HTML needs to be revalidated.

The 5-minute vite build errors checklist

Symptom Most likely cause Fix
Rolldown failed to resolve import Package not installed, or skipped in CI npm install <pkg>; check devDependencies vs CI install flags
Could not resolve './...' Typo, case mismatch, or unknown alias Fix the path; match case exactly; define the alias with an absolute path
does not provide an export named Named import from a CJS-only package Default import + destructure, or use the ESM build
Chunks larger than 500 KiB Static import of a heavy dependency Dynamic import(); split routes; codeSplitting groups
CSS minification error Lightning CSS cannot parse your CSS Fix the syntax; fall back to cssMinify: 'esbuild'
Unexpected token Syntax newer than build.target Lower the target, or add @vitejs/plugin-legacy
Heap out of memory Build exceeds Node’s default heap --max-old-space-size; disable reportCompressedSize and source maps
Cannot find module '@rolldown/binding-...' Native binary for the wrong platform Reinstall on the build machine; never copy node_modules across platforms
Config won’t load esbuild 0.24.1 regression, or deprecated rollupOptions npm update esbuild; rename to rolldownOptions

Most vite build errors are not mysterious. The bundler names the module, names the file, and points at the line. Read those three things before you reach for the nuclear options, fix the one thing the error actually says, and keep your Node version, lockfile, and platform in sync between your laptop and CI. That is the whole discipline — and it is what keeps a red build a five-minute interruption instead of a lost afternoon.

Verified against the Vite 8 documentation (vite.dev) and reproduced Vite 8.3.5 error output, 25 November 2026. Vite 8.0 was released 12 March 2026.

Further Reading & References

Related on HowToShipIt: How to Fix the Most Common Next.js Build Errors, How to Fix React Hydration Errors in Next.js, How to Upgrade to TypeScript 7.

Leave a Comment