How to fix npm ERR! ENOMEM: not enough memory in npm
The ENOMEM error occurs when npm or Node.js runs out of available memory. This often happens with large projects, complex dependency trees, or systems with limited RAM.
Quick fix
Fixes npm ERR! ENOMEM: not enough memory
# Set via environment variable
export NODE_OPTIONS="--max-old-space-size=4096"
npm install
# Or inline
NODE_OPTIONS="--max-old-space-size=4096" npm install- Increase Node.js memory limit
- Check system memory
- Close other applications
- Use npm ci instead
# Set via environment variableexport NODE_OPTIONS="--max-old-space-size=4096"npm install# Or inlineNODE_OPTIONS="--max-old-space-size=4096" npm installnpm ERR! ENOMEM: not enough memory
What this error means
ENOMEM indicates the operating system denied a memory allocation request. This can happen when npm's JavaScript heap fills up, when the system is out of RAM, or when memory limits are imposed (containers, cgroups). npm operations involving many packages, particularly npm install on large projects, can consume significant memory for dependency resolution and file operations.
Typical symptoms
- npm install crashes with memory error
- Process killed by OS (OOM killer)
- JavaScript heap out of memory
- Error during large project install
- CI/CD container runs out of memory
- System becomes unresponsive during install
Common causes
- Large dependency tree
- Complex peer dependency resolution
- Limited system RAM
- Container memory limits
- Memory leak in npm or package
- Many concurrent npm processes
- Background processes consuming memory
How to fix "npm ERR! ENOMEM: not enough memory"
Give Node more heap space:
# Set via environment variable
export NODE_OPTIONS="--max-old-space-size=4096"
npm install
# Or inline
NODE_OPTIONS="--max-old-space-size=4096" npm installValue is in MB (4096 = 4GB).
Verify available RAM:
free -h
# Check what's using memory
top -o %MEMFree up memory:
1. Close browser tabs
2. Stop development servers
3. Close IDEs
4. Stop Docker containers not in use
npm ci uses less memory than npm install:
npm ciIt skips dependency resolution when package-lock.json exists.
Install in smaller batches:
# Install production deps first
npm install --omit=dev
# Then dev dependencies
npm installFor Docker/CI environments:
# Docker Compose
services:
app:
deploy:
resources:
limits:
memory: 4G
# GitHub Actions
jobs:
build:
runs-on: ubuntu-latest-16-coresAdvanced notes
Large monorepos may need 8GB+ for npm operations. Consider using pnpm which is more memory-efficient. For constrained environments, pre-install dependencies in CI and cache node_modules. The --max-old-space-size flag affects Node.js heap; system RAM must still be available. Monitor memory usage during installs to find the right limit.
Frequently asked questions
- What does "npm ERR! ENOMEM: not enough memory" mean?
- ENOMEM indicates the operating system denied a memory allocation request. This can happen when npm's JavaScript heap fills up, when the system is out of RAM, or when memory limits are imposed (containers, cgroups). npm operations involving many packages, particularly npm install on large projects, can consume significant memory for dependency resolution and file operations.
- How do I fix "npm ERR! ENOMEM: not enough memory"?
- The ENOMEM error occurs when npm or Node.js runs out of available memory. This often happens with large projects, complex dependency trees, or systems with limited RAM.
- What causes "npm ERR! ENOMEM: not enough memory"?
- Large dependency tree Complex peer dependency resolution Limited system RAM
- Is the "npm ERR! ENOMEM: not enough memory" 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
- ๐
- ๐