How to fix npm ERR! ENOSPC: no space left on device in npm
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- Check disk space
- Clear npm cache
- Remove node_modules
- Clear temporary files
df -h# Check specific directorydu -sh /homedu -sh ~/.npmdu -sh node_modulesnpm 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
- Disk genuinely full
- npm cache too large
- Many node_modules across projects
- Log files consuming space
- Docker volume out of space
- Inode exhaustion
- Temp files not cleaned up
How to fix "npm ERR! ENOSPC: no space left on device"
Verify space usage:
df -h
# Check specific directory
du -sh /home
du -sh ~/.npm
du -sh node_modulesRemove cached packages:
npm cache clean --force
# Check cache size first
npm cache ls
du -sh ~/.npm/_cacacheClear installed packages:
rm -rf node_modules
# Find and remove all node_modules
find . -name "node_modules" -type d -prune -exec rm -rf {} +Clean system temp:
# Remove old temp files
sudo rm -rf /tmp/*
# Clear npm temp
rm -rf ~/.npm/_logs
rm -rf ~/.npm/_npxVerify inode usage:
df -i
# If low on inodes, find directories with many files
find / -xdev -printf "%h\n" | sort | uniq -c | sort -n | tail -20Remove unneeded files:
# 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/UbuntuAdvanced 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
- ๐npm Official Documentation
- ๐
- ๐