Node.js dev server stops with ENOSPC although the disk has free space
Error: ENOSPC: no space left on device, watch '/path/to/project'Short answer
ENOSPC does not always mean a full disk. On Linux, file watchers use inotify, and each user may create only a limited number of watches. When the limit is reached, adding a watch fails with ENOSPC. Compare the limit with the folder size, raise fs.inotify.max_user_watches, and check disk space as the second cause.
Fix it fast
1Find out which cause you have
Read the last word of the message. A failing watch points to the inotify limit, a failing write points to the disk. Then print both numbers.
cat /proc/sys/fs/inotify/max_user_watches df -h .2Match what you see, then jump to its fix
What does the error look like?
Error: ENOSPC: no space left on device, watch '/path/to/project'Error: ENOSPC: no space left on device, write
Cause 1 of 2
The per-user inotify watch limit is too low for the project
1Check
On Linux, Node.js file watching uses inotify. The kernel caps the number of watches per user, and the call that adds a watch fails with ENOSPC when the user limit is reached. Large node_modules folders and several watchers at once use the limit up quickly.
cat /proc/sys/fs/inotify/max_user_watches
find . -type d -not -path '*/node_modules/*' | wc -l2Fix
Raise the limit. First change it for the running system, then keep it across reboots with a file in /etc/sysctl.d.
echo 524288 | sudo tee /proc/sys/fs/inotify/max_user_watches
echo "fs.inotify.max_user_watches=524288" | sudo tee /etc/sysctl.d/99-inotify.conf3Verify
Read the value back and start the watcher again.
cat /proc/sys/fs/inotify/max_user_watches
npm run devConfirmed by man7.org
Cause 2 of 2
The disk really is full
1Check
A write fails with ENOSPC when the device holding the file has no room for the data. Find which folder holds the space.
df -h
du -xh --max-depth=1 . | sort -h | tail -n 102Fix
Remove what you can regenerate, such as build output and caches, or move large logs elsewhere. Then retry the failed command.
rm -rf .next dist build
npm cache clean --force3Verify
Confirm there is free space again and rerun the command that failed.
df -h .Confirmed by man7.org
How do I stop it coming back?
- Tell the watcher to ignore node_modules and build folders so it adds fewer watches.
- Keep the sysctl.d file in your server setup notes so a new machine gets the same limit.
- Add a disk usage alert to servers that run builds or write logs.
- Run one watcher per project instead of several tools watching the same tree.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine built on the same technologies:
Related fixes
Back end
Application Load Balancer returns 502 for a Node.js target
HTTPCode_ELB_502_Count
An ALB returns 502 when the target gives it something it cannot use: a refused or reset connection, a connection closed mid-request, a bad response, or a header over 32 K.
4 causes, each with a fixBack end
corepack enable fails: permission denied while creating the pnpm link
Internal Error: EACCES: permission denied, symlink '../lib/node_modules/corepack/dist/pnpm.js' -> '/usr/local/bin/pnpm'
corepack enable writes small link files for yarn and pnpm next to your node binary.
2 causes, each with a fixBack end
Create React App says Node is too old, and npm will not run on the new one
npm does not support Node.js v10.19.0
The shell is running an old Node.js that is below the version Create React App needs.
3 causes, each with a fixBack end
firebase deploy cannot load your functions: user code failed to load
Functions codebase could not be analyzed successfully. It may have a syntax or runtime error
The Firebase CLI loads your functions code on your machine before it deploys, to learn which functions exist.
4 causes, each with a fixBack end
firebase deploy stops because the predeploy lint step failed
Error: There was an error deploying functions
The predeploy hook in firebase.json runs npm run lint before every deploy, and a failing hook cancels the deploy.
3 causes, each with a fixBack end
fluent-ffmpeg cannot find the ffmpeg or ffprobe binary
Error: Cannot find ffprobe
fluent-ffmpeg does not bundle ffmpeg.
4 causes, each with a fix