← All fixes
FATAL ERROR: Reached heap limit / JavaScript heap out of memory during build
#138Error
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 yet0 worked0 didn't
Tried it yourself?
Related fixes
Vercel build fails: Command "npm run build" exited with 1 (works locally)
#148Error: Command "npm run build" exited with 1 on Vercel, while the build passes on my machine
bash: tsc: command not found (tool is installed in node_modules, not globally)
#64build.sh: line 1: tsc: command not found
nodenpmtypescriptVerifiedNo reports yet
'vite' is not recognized as an internal or external command (or vite: command not found)
#170'vite' is not recognized as an internal or external command, operable program or batch file.