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.
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.
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-coresLarge 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.
npm ERR! code E401 npm ERR! 401 Unauthorized - Token has expired
Token has expired - npm authentication failure
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 ERR! code EWORKSPACEMISSING npm ERR! Workspace does not exist: packages/missing
How to fix "npm ERR! code EWORKSPACEMISSING - Workspace does not exist" error
npm ERR! code EADDRNOTAVAIL npm ERR! errno EADDRNOTAVAIL npm ERR! Address not available
How to fix "npm ERR! code EADDRNOTAVAIL - Address not available" error