How to fix Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch ...

Problem

On Linux, you see an error message such as

watchpack_error_output.txt
Watchpack Error (watcher): Error: ENOSPC: System limit for number of file watchers reached, watch '/home/uli/dev/myproject/node_modules/@primeuix'

Solution

This error often occurs if your IDE such as visual studio code is watching huge workspaces, most often with node_modules directories.

Generally, you can just increase the limit:

increase_inotify_limits.sh
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
echo fs.inotify.max_user_instances=16384  | sudo tee -a /etc/sysctl.conf
echo fs.inotify.max_queued_events=32768 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p

However I also recommend to configure VS code to not watch those paths:

vscode_watcher_settings.json
"files.watcherExclude": {
  "**/node_modules/**": true,
  "**/dist/**": true,
  "**/.git/**": true
}

Check out similar posts by category: Linux