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.
Fixes npm ERR! ENOSPC: no space left on device
df -h
# Check specific directory
du -sh /home
du -sh ~/.npm
du -sh node_modulesdf -h# Check specific directorydu -sh /homedu -sh ~/.npmdu -sh node_modulesnpm ERR! ENOSPC: no space left on device
On this page
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.
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/UbuntuIn 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.