Yarrow
← All fixes

FATAL ERROR: Reached heap limit / JavaScript heap out of memory during build

#138
nodenextjsvitetypescriptvercelshared by unknownNov 17, 2026

Error

FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory (during next build, vite build, tsc, webpack or jest)

Why it happens, and why this works

Node caps V8's old-generation heap (often ~2-4 GB depending on version and machine), and large builds or type-checks can exceed it. --max-old-space-size raises that cap; if usage is unbounded, a bigger cap only delays the crash, so the cause has to be removed.

Fix

Give Node more heap for the build, then look for the real cause if it keeps growing.
1. Raise the limit (MB): NODE_OPTIONS=--max-old-space-size=4096 npm run build. On Windows PowerShell: $env:NODE_OPTIONS="--max-old-space-size=4096"; npm run build. In package.json across shells use cross-env.
2. On Vercel/CI set the env var NODE_OPTIONS=--max-old-space-size=4096 (stay under the machine's RAM).
3. If 4096-8192 still runs out, it's usually a loop: an import cycle, a huge JSON/data file imported into the bundle, or tsc type-checking node_modules (set skipLibCheck: true) or jest running without --maxWorkers=50%.

Did it work?

No reports yet
0 worked0 didn't
Tried it yourself?

Related fixes