Last updated: Jan 18, 2023
Reading timeยท3 min
The error "System limit for number of file watchers reached" occurs when your system has reached its limit for the number of files being watched.
To solve the error, increase the limit of inotify watchers on your system.
Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/borislav/Documents/one/projects'
Open your shell and run one of the following commands, depending on your OS distribution.
# for Debian, RedHat and other similar Linux distros echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p # for ArchLinux echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system
You can read more about increasing the amount of inotify watchers on your Linux system in this Github repository.
When running your development server or watching your tests, you have exceeded your system's limit for the number of files being watched.
The way to solve the error is to increase the limit of inotify watchers.
The command fs.inotify.max_user_watches=524288
is used to increase the amount
of inotify watchers on your system.
However, the changes won't get persisted between reboots unless you write the new amount of watchers to a file.
You can check the current amount by running the following command:
cat /proc/sys/fs/inotify/max_user_watches
The default number of inotify watchers in Ubuntu 20.04 is 65535
.
524288
is 65535
multiplied by 8
. You can set a more conservative number of
inotify watchers if you'd like and increase the number when necessary.
The tee
command reads the input and writes it to standard output and one or
more files.
# for Debian, RedHat and other similar Linux distros echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p # for ArchLinux echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system
We used the -a
(append) flag to append to the file and not overwrite it.
/etc/sysctl.conf
(Debian, RedHat) or /etc/sysctl.d/40-max-user-watches.conf
(ArchLinux) file on your system, you will see the line that increases the number of inotify watchers at the end.The sudo sysctl -p
command is used to instruct sysctl
to read the values
from the /etc/sysctl.conf
file.
The sysctl --system
command does the same if you use ArchLinux.
In its entirety, the command:
inotify
watchers.sysctl
to read the updated values.You can view the updated amount by running the following command:
cat /proc/sys/fs/inotify/max_user_watches
You should be able to run your development server or your test server after you've made the change.
inotify
watchersIf the error persists, try setting a higher number of inotify watchers.
# for Debian, RedHat and other similar Linux distros echo fs.inotify.max_user_watches=655350 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p # for ArchLinux echo fs.inotify.max_user_watches=655350 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system
Try restarting your Nodemon, React, Angular or Jest server after you've updated the amount of inotify watchers on your system.
If you got the error when using Webpack, try excluding the node_modules
folder
from being watched by setting the watchOptions
property in your
webpack.config.js
file.
module.exports = { //... watchOptions: { ignored: /node_modules/, }, };
This will exclude the node_modules
folder from being watched.
If none of the suggestions helped, try deleting your node_modules
directory
and reinstall your dependencies.
# ๐๏ธ (macOS/Linux) delete node_modules and package-lock.json rm -rf node_modules rm -f package-lock.json rm -f yarn.lock # ๐๏ธ (Windows) delete node_modules and package-lock.json rd /s /q "node_modules" del package-lock.json del -f yarn.lock # ๐๏ธ clean npm cache npm cache clean --force # ๐๏ธ install packages npm install # ๐๏ธ restart your development server
Restart your development server after removing the node_modules
directory and
re-installing your project's dependencies.