Node.js

FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

JavaScript Heap Out of Memory

Node.js ran out of memory while allocating space for JavaScript objects. The default heap limit is around 1.5–2 GB depending on the platform.

Common Causes

Fixes

  1. 1. Increase heap size temporarily
    NODE_OPTIONS=--max-old-space-size=4096 node your-app.js
  2. 2. Use streaming for large files
    const stream = fs.createReadStream('large.json');
    stream.pipe(JSONStream.parse());
  3. 3. Process data in chunks
    for (const chunk of chunks) {
      processChunk(chunk);
      global.gc?.(); // if --expose-gc
    }
  4. 4. Profile with --inspect
    node --inspect --max-old-space-size=4096 app.js

Still not fixed?

Related Errors

DuskTools That Might Help

All Errors