heap out of memory Node.js Origin: Application & API Last updated 9 Oct 2026

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.

Exact message you may see JavaScript heap out of memoryReached heap limit Allocation failedIneffective mark-compacts near heap limit
Seen on: Node.js npm

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

  1. Raise the heap: NODE_OPTIONS=--max-old-space-size=4096
  2. Stream large files instead of reading them whole
  3. Take heap snapshots to find leaks
  4. Keep the heap limit below the container limit

Detailed fix by platform

Node.js

  1. 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

  1. Phase — Build or runtime?
  2. Growth — Memory grows steadily (leak) or spikes?
  3. 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:

Where this error sits

Origin: Application & API. Errors that are often confused with or caused by this one (click to open):

0xC0000005 — The application was unable to start correctly (0xc0000005) / Exception code 0xc0000005 access violation (Windows)0xC0000005Cannot allocate memory — fork: Cannot allocate memory / ENOMEM (Linux)Cannot allocate memorydouble free or corruption — C/C++: free(): double free detected / double free or corruption (out) — Aborted (core dumped) (C/C++)double free or corrup…ELIFECYCLE — npm ERR! code ELIFECYCLE / Command failed with exit code 1 (npm)ELIFECYCLEEXC_BAD_ACCESS — Thread 1: EXC_BAD_ACCESS (code=1, address=0x0) (iOS)EXC_BAD_ACCESSGradle Java heap space — Gradle: Expiring Daemon because JVM heap space is exhausted / java.lang.OutOfMemoryError: Java heap space during build (Android)Gradle Java heap spaceinvalid string length — RangeError: Invalid string length (JavaScript)invalid string lengthJupyter kernel died — The kernel appears to have died. It will restart automatically. (Python)Jupyter kernel diedheap out …

Explore the map of this error Full error map →

🧠 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.