How to fix FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory in npm
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"- Increase Node.js heap size
- Use npm ci instead of install
- Clear npm cache
- Check for memory leaks
# Via environment variableexport NODE_OPTIONS="--max-old-space-size=8192"# For specific commandnode --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
- Node.js heap limit exceeded
- Large dependency tree
- Memory-intensive build process
- Memory leak in code or dependencies
- Too many concurrent operations
- Large files being processed
- Inefficient webpack configuration
How to fix "FATAL ERROR: CALL_AND_RETRY_LAST Allocation failed - JavaScript heap out of memory"
Set higher memory limit:
# 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.
More memory-efficient:
npm cinpm ci skips certain resolution steps that consume memory.
Free up resources:
npm cache clean --force
rm -rf node_modules
npm installMonitor memory during build:
# Watch memory usage
while true; do
ps aux | grep node | awk '{print $6/1024 " MB"}'
sleep 1
doneIf memory grows unbounded, there may be a leak.
Reduce memory usage:
// webpack.config.js
module.exports = {
optimization: {
splitChunks: { chunks: 'all' },
usedExports: true
},
// Disable source maps in production
devtool: false
};Ensure you're using 64-bit:
node -p "process.arch"
# Should show "x64" for 64-bit
# 32-bit has much lower memory limitsAdvanced 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
- ๐npm Official Documentation
- ๐
- ๐