Error: ENOSPC: System limit for number of file watchers reached
Educational use only. Content explains errors and defensive fixes for systems you own or are authorised to test. Do not use any technique here to access data, accounts, or networks without permission.
Root Cause
This is a Linux-specific error that occurs when an application (typically a development server like Webpack, Vite, or Nodemon) attempts to monitor more files for changes than the operating system allows. Linux has a built-in limit on the number of `inotify` watches a single user can create. Modern web projects with massive `node_modules` directories can easily exceed the default limit (often set to 8192), causing the watcher utility to crash.
Fix / Solution
You need to permanently increase the maximum number of `inotify` file watchers allowed by the system. This is done by modifying the `fs.inotify.max_user_watches` system variable. You should also configure your development tools to ignore the `node_modules` directory when watching for file changes, as dependencies rarely change during a standard development session.
Code Snippet
# ❌ Command fails due to ENOSPC
npm run start
# ✅ Increase the limit temporarily
sudo sysctl fs.inotify.max_user_watches=524288
# ✅ Increase the limit permanently
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf
sudo sysctl -p