npm ERR! code ENOSPC
This error matches known, documented patterns with reliable solutions.
Quick Fix (Most Common Solution)
- Free disk space
- Run npm cache clean --force
Seeing "npm ERR! code ENOSPC"? This error can be frustrating, but it's usually fixable. It typically affects your development workflow or system. Below you'll find clear, step-by-step solutions to resolve this issue.
What This Error Means
The disk is full and npm cannot write files.
Frequently documented in developer and vendor support forums.
Not affiliated with browser, OS, or device manufacturers.
New here? Learn why exact error messages matter →
Common Causes
- Disk full
- Too many npm cache files
- Large node_modules
How to Fix
- Free disk space
- Run npm cache clean --force
- Delete unused node_modules folders
Last reviewed: March 2026 How we review solutions
Why This Happens
ENOSPC stands for "Error NO SPaCe" and occurs when npm tries to write a file but the disk partition has no free space remaining. Node.js projects with deep dependency trees generate enormous node_modules directories—a typical React or Next.js project can create 200-400 MB of node_modules, and monorepos with multiple packages can exceed several gigabytes. The npm cache (~/.npm/_cacache) also grows over time as you install different packages across multiple projects, and unlike node_modules it is never automatically cleaned. CI/CD environments are particularly vulnerable because they often run on small disk volumes and accumulate cached data across builds. Docker builds can exhaust the Docker daemon's storage driver—even if the host has free disk space, the Docker overlay filesystem may have its own limits. In cloud development environments (Codespaces, Gitpod, Replit), the workspace has a fixed disk allocation that large dependency trees can fill. The error can also occur when disk quotas are enforced per user (common on shared servers), even if the physical disk has space remaining.
Quick Diagnostic Checklist
- Check available disk space: df -h (Linux/macOS) or dir (Windows)
- Check npm cache size: du -sh ~/.npm
- Clear npm cache: npm cache clean --force
- Remove unused node_modules from other projects
- Check disk quotas: quota -s (Linux) if on a shared server
Recovering from ENOSPC disk full error
# Error output:
# npm ERR! code ENOSPC
# npm ERR! syscall write
# npm ERR! errno -28
# npm ERR! nospc ENOSPC: no space left on device, write
# Step 1: Check disk usage
$ df -h /
# Filesystem Size Used Avail Use%
# /dev/sda1 20G 19G 0.5G 97% <-- Almost full!
# Step 2: Find large directories
$ du -sh ~/.npm node_modules /tmp 2>/dev/null
# 2.1G ~/.npm <-- npm cache is large
# 850M node_modules <-- Current project deps
# 500M /tmp <-- Temp files
# Step 3: Clear npm cache (safe to do anytime)
$ npm cache clean --force
# Cache cleared — freed ~2GB
# Step 4: Remove node_modules from old projects
$ find ~/ -name "node_modules" -type d -maxdepth 3 2>/dev/null
# /home/user/old-project/node_modules <-- Delete these
$ rm -rf ~/old-project/node_modules
# Step 5: Clear system temp files
$ sudo apt clean # Clear apt package cache
$ docker system prune -f # Clear unused Docker data
# Step 6: Retry npm install
$ npm install
Edge Cases & Unusual Scenarios
Docker build layer caching exhausting space
Each Docker build layer is cached separately. Building the same image multiple times with different dependencies creates duplicate layers. Run docker system prune to reclaim space, and use multi-stage builds to minimize final image size.
inode exhaustion instead of byte exhaustion
Some filesystems (ext4) have a fixed number of inodes. node_modules creates thousands of small files that can exhaust inodes while bytes remain available. Check with df -i. The fix is the same: delete unused node_modules and clear the npm cache.
/tmp filling up during npm install
npm uses the system temp directory to extract tarballs. If /tmp is a separate small partition (common on some Linux configurations), it can fill up during installation of large packages. Set npm to use a different temp directory: npm config set tmp ~/npm-tmp.
Optional follow-up
Some users ask whether saving fixes for recurring errors would be useful when the same issue appears again.
Was this explanation helpful?
Frequently Asked Questions
How much space does npm need?
Varies, but 1-2GB free is recommended.
Where is npm cache?
Usually ~/.npm on Unix systems.
How much disk space does a typical Node.js project need?
A typical project needs 200-500 MB for node_modules, plus the npm cache grows to 1-3 GB over time. Monorepos and projects with native addons can require significantly more. Plan for at least 2 GB of free space before running npm install.
Can I move the npm cache to a larger disk?
Yes. Set the cache location with npm config set cache /path/to/large-disk/.npm-cache. This is useful when your home directory is on a small partition but another disk has more space.
Is it safe to delete the npm cache?
Yes, npm cache clean --force is always safe. npm will re-download packages as needed. The only downside is slower subsequent installs until the cache is repopulated.
Related Resources
Also Known As
- npm install error
- npm dependency error
- node package manager error
- npm ERR! message
Common Search Variations
- "npm install not working"
- "npm ERR how to fix"
- "node modules error fix"
- "npm install failed what to do"
- "npm dependency conflict solution"
- "why does npm install fail"
Related Errors
Still Stuck?
Paste a different error message or upload a screenshot to get help instantly.