Grunt watch error - Waiting...Fatal error: watch ENOSPC
Asked Answered
C

7

531

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

Claudelle answered 25/5, 2013 at 10:42 Comment(1)
For anyone viewing this, this is not specific to grunt but any program using inotify underneath. There is a good explanation at unix.stackexchange.com/questions/13751/….Reprehensible
C
1373

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
Claudelle answered 2/7, 2013 at 23:49 Comment(31)
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...Kamp
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.Compliance
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/SysctlImpressible
Is the posted answer for MacOSX?Waly
This seems to have worked for others, but I get an error on OSX...sysctl: illegal option -- pIthaca
npm dedupe cleared it up for me. issueCorsetti
or just htop kill the multiple spawns of same process you may have.Strongarm
@blurd So why would npm dedupe fix this?Wrathful
Ha! Killing dropbox also fixed it :)Usufruct
Arch #2: in response to tnajdek, i had to add that to the file /usr/lib/sysctl.d/50-default.conf insteadHeteromorphic
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 parameterClaudelle
I never got this problem until very recently, only think I know of that has changed is that nodejs was updated. I am not satisfied with the expatiation of this. What is the default limit? Are watches the number of files? I am only watching for .less and .php files cant be that many and I do not run dropbox or anything else just grunt-contrib-watchReno
In my case, the villains were Grunt using LiveReload and Compass, and Sublime watching the files... Thanks a lot!Rev
Thanks for mentioning that @ViniciusPires, re-opening Sublime after grunt serve started successfully fixed the problem for me.Indecent
So log2 524288 is 19. What is the significance of 19? Why does this number work?Indecent
for the record: same problem with Brunch, same solution :)Allodium
For the curious: I had this problem running Grunt from a Docker container. It took me a while to realize that I needed to execute the command from the host OS instead of from the container itself.Valma
It's working here for Ubuntu 14.04. Thank you very much! you've saved my day.Renettarenew
Worked for me in Fedora.Youngs
I honestly have no idea why this works for me and not Extazystas, but it did! Ubuntu 14.04 running foreman with grunt scriptsTheurich
Worked for me with gulp/browserSync on ubuntu 14.04.02Schultz
This is also the solution to another question here on Stack : nextTick error When using Ubuntu (14.04 in my case)Puppetry
Worked like a charm in Fedora 22.Zehe
@mohammed-ramadan I have already given the explanation on one of the answers. Please find the section "explanation: " that has the detailed level explanation.Claudelle
Wonders shall never end! I thought the command was more of sorcery, but makes sense now.Susanasusanetta
Worked for me on Ubuntu 15.10.Malave
@AdityaMP I just found the reason for the "magic" number. To quote "Assuming you set the max at 524288 and all were used (improbable), you'd be using approximately 256MB/512MB of 32-bit/64-bit kernel memory." - from unix.stackexchange.com/questions/13751/…Jestinejesting
Arch linux ([deprecated sysctl.conf][1]): echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system [1]: archlinux.org/news/deprecation-of-etcsysctlconfIncorporate
Caveat: this will increase unswappable memory usage up to 256 or 512 MB, see unix.stackexchange.com/questions/13751/…Tiler
This happens to me on boot. Without any Dropbox (or anything that watch files) installed. Any idea how to check what is watching files, or what is the actual limit?Forestaysail
Getting this error on ubuntu 16.04 sysctl: cannot stat /proc/sys/fs/inotify/max_user_­watches: No such file or directoryWrestling
E
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.

Epochal answered 10/8, 2015 at 18:19 Comment(10)
Thanks for making the pony happy.Lorna
Talking about treating the symptom...I used to do a grunt --force before I found thisDigestible
What exactly it does ? It solved my problem for sure. Thanks @EpochalNucleon
'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/dedupeSquinch
it didn't help, i tried with sudo and now it's working for me.Troytroyer
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 dedupeSoap
I was getting error on running "npm install grunt". The message was "(node) warning: Recursive process.nextTick detected. This will break in the next version of node. Please use setImmediate for recursive deferral.". This solved my problem.Etymon
some more info produced by phpstorm: confluence.jetbrains.com/display/IDEADEV/Inotify+Watches+LimitNihilism
Changing something on the Filesystem for npm can't be right. This answer should be accepted.Hankhanke
Here's more context around vscode- "Visual Studio Code is unable to watch for file changes in this large workspace" (error ENOSPC): code.visualstudio.com/docs/setup/…Gman
R
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.

Rayerayfield answered 9/1, 2017 at 14:41 Comment(1)
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).Paoting
F
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.

Flemming answered 9/10, 2017 at 15:29 Comment(1)
the same with me for vscode but i think it is related to file watches as wellDowning
S
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.

Stickney answered 18/4, 2017 at 16:15 Comment(0)
K
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.

Kingwood answered 16/6, 2019 at 7:29 Comment(0)
B
0

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

Breakthrough answered 28/4, 2020 at 8:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.