Tutorial 📅 November 11, 2025 📖 8 min read

Fix npm ERR! code ENOSPC on VPS - Complete Solution (2025)

Complete guide to fix 'npm ERR! code ENOSPC' error on VPS. Learn causes, solutions, and prevention. Fix disk space issues, inotify limits, and install errors without terminal complexity.

Getting "npm ERR! code ENOSPC" error on your VPS? This frustrating error stops npm installations and builds. This comprehensive guide explains why it happens and provides multiple solutions - including how to fix it without terminal knowledge using VPS Commander.

❌ Common Error Messages:

What is npm ERR! code ENOSPC?

ENOSPC stands for "Error NO SPaCe" and indicates your system has run out of a critical resource. On VPS servers, this error has two main causes:

  1. Actual Disk Space Issue: Your VPS storage is full
  2. File Watcher Limit: Linux inotify watch limit is reached (most common)

The confusing part? The error message says "no space" even when you have plenty of disk space. This is because Linux file watchers also count as "space."

Cause 1: Actual Disk Space Problems

Check Your Disk Usage

First, verify if you actually have disk space issues:

Method 1: Using Terminal

df -h

Look at the "Use%" column. If any partition shows 90%+ usage, you have a space problem.

Method 2: Using VPS Commander (No Terminal)

Solution: Free Up Disk Space

1. Clear npm Cache

Terminal:

npm cache clean --force

VPS Commander:

2. Remove Old node_modules

Finding and removing unused node_modules folders:

Terminal:

find . -name "node_modules" -type d -prune -exec rm -rf '{}' +

VPS Commander:

3. Clean Package Manager Caches

# Yarn cache
yarn cache clean

# pnpm cache
pnpm store prune

# npm cache
npm cache clean --force

4. Remove Old Logs

Terminal:

sudo journalctl --vacuum-time=3d
sudo find /var/log -type f -name "*.log" -delete

VPS Commander:

Cause 2: File Watcher Limit (Most Common)

This is the most common cause of ENOSPC errors on VPS, especially with Node.js development.

What Are File Watchers?

File watchers (inotify) monitor files for changes. Tools like webpack, nodemon, and VS Code use them extensively. Linux systems have a default limit of 8,192 watchers - modern Node.js projects easily exceed this.

Check Current Limit

cat /proc/sys/fs/inotify/max_user_watches

If this shows 8192 or less, you need to increase it.

Solution: Increase inotify Watches Limit

Method 1: Temporary Fix (Terminal)

This fixes the issue until next reboot:

sudo sysctl fs.inotify.max_user_watches=524288
sudo sysctl -p

Method 2: Permanent Fix (Terminal)

Make the change persist across reboots:

echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

Method 3: Using VPS Commander (No Terminal)

  1. Open File Editor in VPS Commander
  2. Navigate to /etc/sysctl.conf
  3. Add this line at the end:
    fs.inotify.max_user_watches=524288
  4. Save the file
  5. Use Workflow Mode to run "Reload System Settings"

Or simply ask the AI Assistant:

💬 AI Assistant: "Increase inotify watches limit to 524288"
AI will execute the commands and verify the fix automatically.

Why 524288 Watches?

Each inotify watch consumes about 1KB of kernel memory. 524,288 watches ≈ 512MB RAM, which is reasonable for modern VPS servers. This limit supports:

Additional Solutions for ENOSPC Errors

1. Increase Swap Space

If your VPS has limited RAM, add swap space:

Terminal:

sudo fallocate -l 2G /swapfile
sudo chmod 600 /swapfile
sudo mkswap /swapfile
sudo swapon /swapfile

VPS Commander:

2. Optimize npm Install

Use these flags to reduce disk usage during installation:

# Skip optional dependencies
npm install --no-optional

# Use production mode
npm install --production

# Use npm ci instead of install
npm ci --production

3. Switch to pnpm (Saves 50-70% Disk Space)

pnpm uses hard links instead of copying packages:

npm install -g pnpm
pnpm install

A project that takes 500MB with npm takes only 150MB with pnpm!

4. Use .dockerignore or .gitignore

Prevent copying node_modules accidentally:

# .dockerignore
node_modules/
*.log
.npm
.cache

Prevention: Avoid ENOSPC Errors

1. Monitor Disk Usage Regularly

VPS Commander Dashboard shows real-time disk usage. Set up alerts when disk reaches 80% capacity.

2. Use .npmrc Configuration

Create .npmrc in your project:

# Reduce cache size
cache-max=1000

# Prefer offline mode
prefer-offline=true

# Progress false (saves memory)
progress=false

3. Regular Cleanup Script

Create a weekly cleanup cron job:

# Clean npm cache weekly
0 0 * * 0 npm cache clean --force

Or use VPS Commander's Scheduled Tasks to automate this visually.

4. Upgrade VPS Storage

If you consistently hit storage limits, upgrade your VPS plan. Most providers offer easy upgrades starting at $5-10/month.

Fix ENOSPC During Specific Operations

During npm install

# Increase memory limit
node --max-old-space-size=4096 $(which npm) install

During webpack build

# Increase Node.js memory
export NODE_OPTIONS="--max-old-space-size=4096"
npm run build

During Docker build

# Use BuildKit with better caching
DOCKER_BUILDKIT=1 docker build -t myapp .

VPS Commander: The Easy Way to Fix ENOSPC

Why Use VPS Commander?

Fixing ENOSPC with VPS Commander in 3 Steps

  1. Diagnose: Check disk usage in Server Stats dashboard
  2. Fix: Use AI Assistant: "Fix npm ENOSPC error"
  3. Verify: AI confirms the fix and runs npm install successfully

Time required: 2-3 minutes (vs 20-30 minutes manually troubleshooting)

Troubleshooting: Error Still Persists

1. Check Specific Directory Space

du -sh /tmp
du -sh ~/.npm
du -sh node_modules

2. Check Inode Usage

Sometimes you run out of inodes (file pointers) not space:

df -i

If "IUse%" is near 100%, delete many small files.

3. Restart Node.js Process

pm2 restart all

4. Reboot VPS

Last resort if all else fails:

sudo reboot

With VPS Commander, just click "Restart Server" button.

Platform-Specific Solutions

Ubuntu/Debian VPS

sudo apt clean
sudo apt autoremove
sudo apt autoclean

CentOS/RHEL VPS

sudo yum clean all
sudo package-cleanup --oldkernels --count=1

Docker Containers

docker system prune -a
docker volume prune

Conclusion: Never Let ENOSPC Stop You

The npm ENOSPC error is frustrating but easily fixable. In most cases, it's the inotify watches limit, not actual disk space. With VPS Commander, you can diagnose and fix these issues without memorizing complex Linux commands.

Quick Recap:

Fix ENOSPC Errors Without Terminal

Use VPS Commander's visual interface and AI Assistant to solve npm errors in minutes.

Start Free Trial →

Frequently Asked Questions

Why does npm say "no space" when I have 50GB free?

The error message is misleading. It's usually the inotify watches limit (8,192 default), not disk space. Increase it to 524,288.

Is 524288 watches safe for my VPS?

Yes! It uses about 512MB RAM. Any VPS with 1GB+ RAM handles this easily.

Will this fix persist after reboot?

Only if you edit /etc/sysctl.conf. The sysctl command alone is temporary.

Can I use this fix on shared hosting?

No. Shared hosting doesn't give you root access. You need VPS for system-level changes.

Does VPS Commander work with all VPS providers?

Yes! Works with DigitalOcean, Linode, Vultr, AWS, Google Cloud, Azure, Hetzner, OVH, and any VPS with SSH access.