How to fix npm ERR! ENOSPC: no space left on device in npm

npmBEGINNERHIGHUpdated Dec 6, 2025ยท 234 views

The ENOSPC error occurs when npm cannot write files due to insufficient disk space. Clear npm cache, remove node_modules, or free up disk space to resolve this.

Quick fix

Fixes npm ERR! ENOSPC: no space left on device

df -h

# Check specific directory
du -sh /home
du -sh ~/.npm
du -sh node_modules
  1. Check disk space
  2. Clear npm cache
  3. Remove node_modules
  4. Clear temporary files
npm โ€” error
df -h
# Check specific directory
du -sh /home
du -sh ~/.npm
du -sh node_modules
npm ERR! ENOSPC: no space left on device

What this error means

ENOSPC is a system-level error indicating the filesystem has no available space. npm needs to write files during installation - packages, cache data, and temporary files. When the disk is full, all write operations fail. This error can also occur on systems with inode exhaustion (many small files) even if there's technically space available.

Typical symptoms

  • npm install fails with ENOSPC
  • Error mentions "no space left"
  • Other programs also failing to write
  • CI/CD runner out of space
  • npm cache grown very large
  • node_modules consuming all space

Common causes

  1. Disk genuinely full
  2. npm cache too large
  3. Many node_modules across projects
  4. Log files consuming space
  5. Docker volume out of space
  6. Inode exhaustion
  7. Temp files not cleaned up

How to fix "npm ERR! ENOSPC: no space left on device"

1Check disk space

Verify space usage:

bash
df -h

# Check specific directory
du -sh /home
du -sh ~/.npm
du -sh node_modules
2Clear npm cache

Remove cached packages:

bash
npm cache clean --force

# Check cache size first
npm cache ls
du -sh ~/.npm/_cacache
3Remove node_modules

Clear installed packages:

bash
rm -rf node_modules

# Find and remove all node_modules
find . -name "node_modules" -type d -prune -exec rm -rf {} +
4Clear temporary files

Clean system temp:

bash
# Remove old temp files
sudo rm -rf /tmp/*

# Clear npm temp
rm -rf ~/.npm/_logs
rm -rf ~/.npm/_npx
5Check for inode exhaustion

Verify inode usage:

bash
df -i

# If low on inodes, find directories with many files
find / -xdev -printf "%h\n" | sort | uniq -c | sort -n | tail -20
6Free up disk space

Remove unneeded files:

bash
# Find large files
find / -type f -size +100M 2>/dev/null

# Clean docker
docker system prune -a

# Clean package manager cache
sudo apt clean  # Debian/Ubuntu

Advanced notes

In CI/CD, use cache strategies that share npm cache across runs but clean node_modules. Docker images should use multi-stage builds to minimize size. Consider using pnpm for space-efficient dependency management. Set up monitoring for disk space to catch issues early. For persistent issues, consider expanding disk capacity.

Frequently asked questions

What does "npm ERR! ENOSPC: no space left on device" mean?
ENOSPC is a system-level error indicating the filesystem has no available space. npm needs to write files during installation - packages, cache data, and temporary files. When the disk is full, all write operations fail.
How do I fix "npm ERR! ENOSPC: no space left on device"?
The ENOSPC error occurs when npm cannot write files due to insufficient disk space. Clear npm cache, remove node_modules, or free up disk space to resolve this.
What causes "npm ERR! ENOSPC: no space left on device"?
Disk genuinely full npm cache too large Many node_modules across projects
Is the "npm ERR! ENOSPC: no space left on device" 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