FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory
The V8 heap hit its limit — a large build (webpack, tsc, Next.js) needs more memory, or the app leaks.
JavaScript heap out of memoryReached heap limit Allocation failedIneffective mark-compacts near heap limit Meaning
Node caps the heap (roughly 2–4 GB depending on version and system memory). Builds of large projects and memory leaks in long-running servers both hit it.
Common causes
- Large frontend/TypeScript builds
- Memory leak (growing caches, listeners, global arrays)
- Loading huge JSON/files into memory
- Container memory smaller than the heap limit
⚡ Quick fix
- Raise the heap:
NODE_OPTIONS=--max-old-space-size=4096 - Stream large files instead of reading them whole
- Take heap snapshots to find leaks
- Keep the heap limit below the container limit
Detailed fix by platform
Node.js
- Raise heap for a build:bash
NODE_OPTIONS=--max-old-space-size=4096 npm run build node --inspect app.js # then Chrome DevTools → Memory → heap snapshots to find leaks
How to diagnose
- Phase — Build or runtime?
- Growth — Memory grows steadily (leak) or spikes?
- Limits — Heap vs container memory
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
Most viewed in Node.js
Other ways to find it
Where this error sits
Origin: Application & API. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 9 Oct 2026