Visual Studio Code is unable to watch for file changes in this large workspace (error ENOSPC)

While using Visual Studio code whenever there is a project with lots of files, there are chances of seeing this error. Visual Studio Code normally monitors the changes made in your files, new files added, removed or modified and it is logged by our version control system. The changes in VCS are only visible after we stash the changes or add them. But before adding the changed files in a version control system with a commit, the IDE is responsible for monitoring the changes in your files.

For that we can check what is the limit of your VS Code file watcher. You can do it by running the following command in your terminal:

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

Default file watcher limit in my Visual Studio Code was 8MB. Now we can increase this and this way your Visual Studio code can watch the changes made in different files. Run the following from your terminal to increase the file watcher limit:

echo /etc/sysctl.conf >> fs.inotify.max_user_watches=524288

This will increase the limit to around 524288 which is the maximum number of files your VSCode can watch.