Skip to content
Latchkey

Vite "JavaScript heap out of memory" on Large App Builds in CI

A large vite build runs Rollup over thousands of modules, and the Node process can exhaust V8's heap on a constrained runner. It aborts with the same OOM as any other Node build.

What this error means

vite build dies with FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory, usually late in the production Rollup pass, on a runner with less RAM than your laptop.

vite
transforming...
✓ 3120 modules transformed.
rendering chunks...
<--- Last few GCs --->
FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory

Common causes

Heap default too low for a big Rollup pass

Many modules, large source maps, and heavy chunking inflate peak memory beyond V8's default old-space cap.

Constrained CI runner

A small runner or container memory cap gives Node less RAM than the build peak, so it OOMs where a bigger machine would not.

How to fix it

Raise Node's heap and trim source maps

Give V8 more old-space and reduce source-map cost for the build.

Terminal
export NODE_OPTIONS=--max-old-space-size=4096
vite build
# vite.config.ts: build: { sourcemap: false } // or 'hidden' in CI

Split chunks and lazy-load routes

  1. Use build.rollupOptions.output.manualChunks to break up large vendor chunks.
  2. Lazy-load routes/components so fewer modules render at once.
  3. Run the build on a larger runner for genuinely large apps.

How to prevent it

  • Set a sensible --max-old-space-size for the build job.
  • Trim source maps and split chunks to lower peak memory.
  • Faster managed runners such as Latchkey offer more RAM plus dependency caching so large Vite builds complete under the heap ceiling and transient OOMs are auto-retried.

Frequently asked questions

What causes "vite build OOM"?
Many modules, large source maps, and heavy chunking inflate peak memory beyond V8's default old-space cap.
How do I fix vite build OOM?
Give V8 more old-space and reduce source-map cost for the build.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.

Related guides

References

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