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.
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 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.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026