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.
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.
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 limitsThe 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.
npm error code E401 npm error Incorrect or missing password.
How to fix 'E401 Unable to authenticate' errors with npm private registries
npm ERR! code EAI_NODATA npm ERR! errno EAI_NODATA npm ERR! getaddrinfo EAI_NODATA registry.npmjs.org
How to fix "npm ERR! code EAI_NODATA - getaddrinfo EAI_NODATA"
npm ERR! code EMPTYPACKAGE npm ERR! Package contains no files
How to fix 'npm ERR! code EMPTYPACKAGE' - Package contains no files
npm notice access token expired or revoked. Please try logging in again.
Token has expired - npm authentication failure
npm ERR! code EAI_AGAIN
How to fix "EAI_AGAIN" in npm