How to fix FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory in npm

npmINTERMEDIATEHIGHUpdated Dec 6, 2025ยท 200 views

The OOM killed error occurs when npm or Node.js exhausts available memory during operations like install or build. Increase memory limits or optimize the operation.

Quick fix

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

# Via environment variable
export NODE_OPTIONS="--max-old-space-size=8192"

# For specific command
node --max-old-space-size=8192 script.js

# In npm script
"build": "node --max-old-space-size=4096 ./node_modules/.bin/webpack"
  1. Increase Node.js heap size
  2. Use npm ci instead of install
  3. Clear npm cache
  4. Check for memory leaks
npm โ€” error
# Via environment variable
export NODE_OPTIONS="--max-old-space-size=8192"
# For specific command
node --max-old-space-size=8192 script.js
# In npm script
"build": "node --max-old-space-size=4096 ./node_modules/.bin/webpack"
FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory

What this error means

OOM (Out of Memory) errors occur when Node.js's V8 JavaScript engine cannot allocate more memory for the heap. By default, Node.js has a memory limit (around 1.4GB on 64-bit systems) that can be exceeded during memory-intensive operations. This is different from system OOM (exit code 137) - this is Node.js's internal heap limit being exceeded before the OS kills the process.

Typical symptoms

  • Fatal error about heap out of memory
  • CALL_AND_RETRY_LAST allocation failed
  • JavaScript heap out of memory
  • Build process crashes
  • npm install fails on large projects
  • Node process becomes unresponsive

Common causes

  1. Node.js heap limit exceeded
  2. Large dependency tree
  3. Memory-intensive build process
  4. Memory leak in code or dependencies
  5. Too many concurrent operations
  6. Large files being processed
  7. Inefficient webpack configuration

How to fix "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory"

1Increase Node.js heap size

Set higher memory limit:

bash
# Via environment variable
export NODE_OPTIONS="--max-old-space-size=8192"

# For specific command
node --max-old-space-size=8192 script.js

# In npm script
"build": "node --max-old-space-size=4096 ./node_modules/.bin/webpack"

Value is in MB.

2Use npm ci instead of install

More memory-efficient:

bash
npm ci

npm ci skips certain resolution steps that consume memory.

3Clear npm cache

Free up resources:

bash
npm cache clean --force
rm -rf node_modules
npm install
4Check for memory leaks

Monitor memory during build:

bash
# Watch memory usage
while true; do
  ps aux | grep node | awk '{print $6/1024 " MB"}'
  sleep 1
done

If memory grows unbounded, there may be a leak.

5Optimize webpack/bundler

Reduce memory usage:

javascript
// webpack.config.js
module.exports = {
  optimization: {
    splitChunks: { chunks: 'all' },
    usedExports: true
  },
  // Disable source maps in production
  devtool: false
};
6Use 64-bit Node.js

Ensure you're using 64-bit:

bash
node -p "process.arch"
# Should show "x64" for 64-bit

# 32-bit has much lower memory limits

Advanced notes

The default heap limit varies by Node.js version and system architecture. Use --expose-gc and global.gc() for manual garbage collection in memory-critical operations. Consider using Worker threads for memory-intensive parallel operations. For builds, incremental compilation and caching significantly reduce memory pressure. Monitor with --inspect and Chrome DevTools for memory profiling.

Frequently asked questions

What does "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap o" mean?
js's V8 JavaScript engine cannot allocate more memory for the heap. 4GB on 64-bit systems) that can be exceeded during memory-intensive operations. js's internal heap limit being exceeded before the OS kills the process.
How do I fix "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap o"?
The OOM killed error occurs when npm or Node.js exhausts available memory during operations like install or build. Increase memory limits or optimize the operation.
What causes "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap o"?
Node.js heap limit exceeded Large dependency tree Memory-intensive build process
Is the "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap o" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading