Got ‘Error: ENOSPC: System limit for number of file watchers reached’ Error? — Big Fat Software, Inc.

Big Fat Software
2 min readNov 3, 2020

Well, we have a solution for this…

The quickest and easiest solution is:

# first paste this to terminal echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf # followed by this sudo sysctl -p

Longterm Fixes:

Exclude some directories from the VS Code file watcher with the files.watcherExclude setting.

"files.watcherExclude": {"**/.git/objects/**": true,"**/.git/subtree-cache/**": true,"**/node_modules/*/**": true}

Explanation

This error is known to occur in Linux environment.

The error occurs when the pre-set limit in either your code-base / config files / editor config / dependencies / environment variables or IDE has been reached. It typically occurs when the number of files to be watched gets too big or when the workspace is large and contains too many files to watch.

To view the current limits

cat /proc/sys/fs/inotify/max_user_watches

Ubuntu Lucid’s (64bit) inotify limit is set to 8192.

I run Ubuntu on this machine too:

$ lsb_release -a
No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu 18.04.5 LTS
Release: 18.04
Codename: bionic

$ cat /etc/*-release
DISTRIB_ID=Ubuntu
DISTRIB_RELEASE=18.04
DISTRIB_CODENAME=bionic
DISTRIB_DESCRIPTION="Ubuntu 18.04.5 LTS"
NAME="Ubuntu"
VERSION="18.04.5 LTS (Bionic Beaver)"
ID=ubuntu
ID_LIKE=debian
PRETTY_NAME="Ubuntu 18.04.5 LTS"
VERSION_ID="18.04"
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
VERSION_CODENAME=bionic
UBUNTU_CODENAME=bionic

And when I checked the limit, it turned out to be: 8192

$ cat /proc/sys/fs/inotify/max_user_watches 8192

To increase the limits

The limit can be increased to its maximum by editing /etc/sysctl.conf (except on Arch Linux) by adding this line to the end of the file:

fs.inotify.max_user_watches=524288

The new value can then be loaded in by running sudo sysctl -p.

524288 is the maximum value.

To increase the limits permanently

$ echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf $ sudo sysctl -p

Known Occurences

Typically users of Visual Studio Code will run into this problem more frequently than anybody else.

But there are other instances too when this error can happen.

React Application

Starting the development server... node:events:304 throw er; // Unhandled 'error' event ^ Error: ENOSPC: System limit for number of file watchers reached, watch '/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/public' at FSWatcher.<computed> (node:internal/fs/watchers:218:26) at Object.watch (node:fs:1529:34) at createFsWatchInstance (/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/node_modules/chokidar/lib/nodefs-handler.js:38:15) at setFsWatchListener (/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/node_modules/chokidar/lib/nodefs-handler.js:81:15) at FSWatcher.NodeFsHandler._watchWithNodeFs (/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/node_modules/chokidar/lib/nodefs-handler.js:233:14) at FSWatcher.NodeFsHandler._handleDir (/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/node_modules/chokidar/lib/nodefs-handler.js:429:19) at FSWatcher.<anonymous> (/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/node_modules/chokidar/lib/nodefs-handler.js:477:19) at FSWatcher.<anonymous> (/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/node_modules/chokidar/lib/nodefs-handler.js:482:16) at FSReqCallback.oncomplete (node:fs:184:5) Emitted 'error' event on FSWatcher instance at: at FSWatcher._handleError (/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/node_modules/chokidar/index.js:260:10) at createFsWatchInstance (/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/node_modules/chokidar/lib/nodefs-handler.js:40:5) at setFsWatchListener (/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/node_modules/chokidar/lib/nodefs-handler.js:81:15) [... lines matching original stack trace ...] at FSReqCallback.oncomplete (node:fs:184:5) { errno: -28, syscall: 'watch', code: 'ENOSPC', path: '/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/public', filename: '/home/bigfatsoftwareinc/Documents/Projects/funky-wonka/public' } error Command failed with exit code 1. info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

Originally published at http://bigfatsoftwareinc.wordpress.com on November 3, 2020.

--

--