531

Why do I get the Waiting...Fatal error: watch ENOSPC when I run the watch task ? How do I solve this issue?

1

7 Answers 7

1372

After doing some research found the solution. Run the below command.

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

For Arch Linux add this line to /etc/sysctl.d/99-sysctl.conf:

fs.inotify.max_user_watches=524288
31
  • 47
    Well, it seems to have solved my problem... But how? Why? Do you have any sources that explain what is happening (or was happening). Or may you yourself do it? Anyway, thanks... Commented Aug 7, 2013 at 1:10
  • 116
    The system has a limit to how many files can be watched by a user. You can run out of watches pretty quickly if you have Grunt running with other programs like Dropbox. This command increases the maximum amount of watches a user can have. Commented Sep 3, 2013 at 19:28
  • 62
    For Arch Linux add fs.inotify.max_user_watches=524288 to /etc/sysctl.d/99-sysctl.conf and then execute sysctl --system. This will also persist across reboots. For more details: wiki.archlinux.org/index.php/Sysctl
    – tnajdek
    Commented Sep 27, 2013 at 9:20
  • 38
    npm dedupe cleared it up for me. issue Commented Mar 4, 2014 at 2:05
  • 25
    explanation: echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf writes at the end of the file /etc/sysctl.conf the line "fs.inotify.max_user_watches=524288" sudo sysctl -p reconfigures the kernel at runtime, loading the file /etc/sysctl.conf as a parameter
    – kds
    Commented Oct 11, 2014 at 7:26
190

Any time you need to run sudo something ... to fix something, you should be pausing to think about what's going on. While the accepted answer here is perfectly valid, it's treating the symptom rather than the problem. Sorta the equivalent of buying bigger saddlebags to solve the problem of: error, cannot load more garbage onto pony. Pony has so much garbage already loaded, that pony is fainting with exhaustion.

An alternative (perhaps comparable to taking excess garbage off of pony and placing in the dump), is to run:

npm dedupe

Then go congratulate yourself for making pony happy.

9
  • 2
    What exactly it does ? It solved my problem for sure. Thanks @grenade
    – Arjun K R
    Commented Nov 5, 2015 at 5:26
  • 4
    'npm dedupe' command walks through your npm module tree and moves every package up in the tree as much as possible. The result is a flat tree. It moves a package even when it is not duplicated. You can read more about what happens to different versions of modules in this case, at docs.npmjs.com/cli/dedupe
    – Arun Reddy
    Commented Nov 18, 2015 at 4:19
  • 1
    it didn't help, i tried with sudo and now it's working for me.
    – asedsami
    Commented Jan 19, 2016 at 1:19
  • 6
    In my case my problem seems to be to have Dropbox installed which seems to use a lot of watches. So I had to use: fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p as in the accepted answer, but +1 for teach me npm dedupe Commented Apr 6, 2016 at 15:22
  • 1
    Changing something on the Filesystem for npm can't be right. This answer should be accepted.
    – kiltek
    Commented May 24, 2018 at 9:51
38

After trying grenade's answer you may use a temporary fix:

sudo bash -c 'echo 524288 > /proc/sys/fs/inotify/max_user_watches'

This does the same thing as kds's answer, but without persisting the changes. This is useful if the error just occurs after some uptime of your system.

1
  • 3
    This should be the accepted answer as the problem is naturally caused by what's running at the moment and not by a bad configuration (see the "pony" example).
    – arielnmz
    Commented Feb 11, 2017 at 16:25
8

To find out who's making inotify instances, try this command (source):

for foo in /proc/*/fd/*; do readlink -f $foo; done | grep inotify | sort | uniq -c | sort -nr

Mine looked like this:

 25 /proc/2857/fd/anon_inode:inotify
  9 /proc/2880/fd/anon_inode:inotify
  4 /proc/1375/fd/anon_inode:inotify
  3 /proc/1851/fd/anon_inode:inotify
  2 /proc/2611/fd/anon_inode:inotify
  2 /proc/2414/fd/anon_inode:inotify
  1 /proc/2992/fd/anon_inode:inotify

Using ps -p 2857, I was able to identify process 2857 as sublime_text. Only after closing all sublime windows was I able to run my node script.

1
  • the same with me for vscode but i think it is related to file watches as well
    – pcnate
    Commented Feb 13, 2018 at 21:45
3

I ran into this error after my client PC crashed, the jest --watch command I was running on the server persisted, and I tried to run jest --watch again.

The addition to /etc/sysctl.conf described in the answers above worked around this issue, but it was also important to find my old process via ps aux | grep node and kill it.

0

In my case it was related to vs-code running on my Linux machine. I ignored a warning which popped up about file watcher bla bla. The solution is on the vs-code docs page for linux https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc

The solution is almost same (if not same) as the accepted answers, just has more explanation for anyone who gets here after running into the issues from vs-code.

0

In my case I found that I have an aggressive plugin for Vim, just restarted it.

Not the answer you're looking for? Browse other questions tagged or ask your own question.