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 (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:

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:

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