How to fix npm ERR! ENOMEM: not enough memory in npm

npmINTERMEDIATEHIGHUpdated Dec 6, 2025ยท 157 views

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
  1. Increase Node.js memory limit
  2. Check system memory
  3. Close other applications
  4. Use npm ci instead
npm โ€” error
# 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
npm 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

  1. Large dependency tree
  2. Complex peer dependency resolution
  3. Limited system RAM
  4. Container memory limits
  5. Memory leak in npm or package
  6. Many concurrent npm processes
  7. Background processes consuming memory

How to fix "npm ERR! ENOMEM: not enough memory"

1Increase Node.js memory limit

Give Node more heap space:

bash
# 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

Value is in MB (4096 = 4GB).

2Check system memory

Verify available RAM:

bash
free -h

# Check what's using memory
top -o %MEM
3Close other applications

Free up memory:

1. Close browser tabs
2. Stop development servers
3. Close IDEs
4. Stop Docker containers not in use

4Use npm ci instead

npm ci uses less memory than npm install:

bash
npm ci

It skips dependency resolution when package-lock.json exists.

5Split installation

Install in smaller batches:

bash
# Install production deps first
npm install --omit=dev

# Then dev dependencies
npm install
6Increase container limits

For Docker/CI environments:

yaml
# Docker Compose
services:
  app:
    deploy:
      resources:
        limits:
          memory: 4G

# GitHub Actions
jobs:
  build:
    runs-on: ubuntu-latest-16-cores

Advanced 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