gatsby: Error: ENOSPC: System limit for number of file watchers reached, watch '/home/foldername/abcrypto/static'
Description
The web app compiles but when I reload the website, the compilation end with an error.
Steps to reproduce
Just type gatsby develop
and if you click an article for example or you reload (ctrl + r) the website compilation will end.
Repo: There you go.
Expected result
gatsby develop
should work.
Actual result
success open and validate gatsby-configs — 0.015 s
success load plugins — 0.382 s
success onPreInit — 0.606 s
success delete html and css files from previous builds — 0.133 s
success initialize cache — 0.013 s
success copy gatsby files — 0.052 s
success onPreBootstrap — 0.006 s
success source and transform nodes — 0.164 s
success building schema — 0.393 s
success createPages — 0.086 s
success createPagesStatefully — 0.072 s
success onPreExtractQueries — 0.006 s
success update schema — 0.224 s
success extract queries from components — 0.216 s
success run graphql queries — 0.164 s — 14/14 88.14 queries/second
success write out page data — 0.004 s
success write out redirect data — 0.001 s
⢀ onPostBootstrapdone generating icons for manifest
success onPostBootstrap — 0.274 s
info bootstrap finished - 4.655 s
DONE Compiled successfully in 1926ms 1:43:58 AM
You can now view abcrypto in the browser.
http://localhost:8000/
View GraphiQL, an in-browser IDE, to explore your site's data and schema
http://localhost:8000/___graphql
Note that the development build is not optimized.
To create a production build, use gatsby build
ℹ 「wdm」:
ℹ 「wdm」: Compiled successfully.
error UNHANDLED EXCEPTION
Error: ENOSPC: System limit for number of file watchers reached, watch '/home/foldername/abcrypto/static'
- watchers.js:165 FSWatcher.start
internal/fs/watchers.js:165:26
- nodefs-handler.js:37 createFsWatchInstance
[abcrypto]/[chokidar]/lib/nodefs-handler.js:37:15
- nodefs-handler.js:80 setFsWatchListener
[abcrypto]/[chokidar]/lib/nodefs-handler.js:80:15
- nodefs-handler.js:232 FSWatcher.NodeFsHandler._watchWithNodeFs
[abcrypto]/[chokidar]/lib/nodefs-handler.js:232:14
- nodefs-handler.js:414 FSWatcher.NodeFsHandler._handleDir
[abcrypto]/[chokidar]/lib/nodefs-handler.js:414:19
- nodefs-handler.js:462 FSWatcher.<anonymous>
[abcrypto]/[chokidar]/lib/nodefs-handler.js:462:19
- nodefs-handler.js:467 FSWatcher.<anonymous>
[abcrypto]/[chokidar]/lib/nodefs-handler.js:467:16
Environment
System:
OS: Linux 4.20 Fedora 29 (Workstation Edition) 29 (Workstation Edition)
CPU: (4) x64 Intel(R) Core(TM) i5-5300U CPU @ 2.30GHz
Shell: 4.4.23 - /bin/bash
Binaries:
Node: 11.3.0 - ~/.nvm/versions/node/v11.3.0/bin/node
Yarn: 1.12.3 - /var/lib/snapd/snap/bin/yarn
npm: 6.7.0 - ~/.nvm/versions/node/v11.3.0/bin/npm
Languages:
Python: 2.7.15 - /usr/bin/python
Browsers:
Firefox: 64.0.2
npmPackages:
gatsby: ^2.0.104 => 2.0.104
gatsby-cli: ^2.4.8 => 2.4.8
gatsby-image: ^2.0.29 => 2.0.29
gatsby-plugin-catch-links: ^2.0.9 => 2.0.9
gatsby-plugin-feed: ^2.0.12 => 2.0.12
gatsby-plugin-google-analytics: ^2.0.12 => 2.0.12
gatsby-plugin-manifest: ^2.0.14 => 2.0.14
gatsby-plugin-offline: ^2.0.22 => 2.0.22
gatsby-plugin-react-helmet: ^3.0.0 => 3.0.5
gatsby-plugin-sharp: ^2.0.18 => 2.0.18
gatsby-plugin-typography: ^2.2.6 => 2.2.6
gatsby-remark-copy-linked-files: ^2.0.5 => 2.0.8
gatsby-remark-images: ^2.0.4 => 2.0.6
gatsby-remark-prismjs: ^3.2.3 => 3.2.3
gatsby-remark-responsive-iframe: ^2.0.5 => 2.0.8
gatsby-remark-smartypants: ^2.0.5 => 2.0.7
gatsby-source-filesystem: ^2.0.18 => 2.0.18
gatsby-transformer-remark: ^2.2.2 => 2.2.2
gatsby-transformer-sharp: ^2.1.12 => 2.1.12
npmGlobalPackages:
gatsby-cli: 2.4.8
gatsby: 2.0.98
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 34
- Comments: 107 (14 by maintainers)
Links to this issue
Commits related to this issue
- add troubleshooting for file watching limits solution per https://github.com/gatsbyjs/gatsby/issues/11406#issuecomment-458769756 — committed to tsnieman/learn-react-hooks by tsnieman 5 years ago
- add troubleshooting for file watching limits (#7) solution per https://github.com/gatsbyjs/gatsby/issues/11406#issuecomment-458769756 — committed to epicweb-dev/react-hooks by tsnieman 5 years ago
- add troubleshooting for file watching limits (#7) solution per https://github.com/gatsbyjs/gatsby/issues/11406#issuecomment-458769756 — committed to codegod2222/react-hook by codegod2222 5 years ago
- add troubleshooting for file watching limits (#7) solution per https://github.com/gatsbyjs/gatsby/issues/11406#issuecomment-458769756 — committed to pinocchio338/hooks by pinocchio338 5 years ago
- add troubleshooting for file watching limits (#7) solution per https://github.com/gatsbyjs/gatsby/issues/11406#issuecomment-458769756 — committed to topstack1226/react-hooks by topstack1226 5 years ago
- add troubleshooting for file watching limits (#7) solution per https://github.com/gatsbyjs/gatsby/issues/11406#issuecomment-458769756 — committed to secretsuperstar1109/react-hooks by secretsuperstar1109 5 years ago
It’s hitting your system’s file watchers limit
Try
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Read more about what’s happening at https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details
Alright I restarted the computer, and now everything works fine again.
thank you very much!!!
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
workedI solved this way https://code.visualstudio.com/docs/setup/linux “Visual Studio Code is unable to watch for file changes in this large workspace” (error ENOSPC)#
cat /proc/sys/fs/inotify/max_user_watches
fs.inotify.max_user_watches=524288
Serve your app as root…It’s work!
Run sudo npm run serve inside you app folder or run this commands as below:
Noooooooo don’t run your app as root! 💀 🚨 That can cause all kinds of security problems!
thanks. it’s really helpfull
it saved my day
Thanks man , you are a hero
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Give me the error:
sysctl: illegal option -- p
Using on MacOS
I ran this line of code in a react-app and everything went back to normal again, thanks!!
instead of increase max_user_watches, webpack watcher should not watch 1 million file inside node_modules!
export CHOKIDAR_USEPOLLING=1 worked.
I still get this issue with Gatsby 2.13.73, and as @good-idea wrote, manually re-deploying is not a viable long term solution especially when making websites for clients with CMS. Why do files even need to be “watched” when building for production?
I got it today too and did a “clear cache and redeploy” and it worked.
This is the actual solution in my case. It turned out that my watcher exclude pattern had an error. It excluded
**/node_modules/*/**
instead of**/node_modules/**
.Increasing the system’s
fs.inotify.max_user_watches
only helped counter the symptoms of this error, and didn’t help any more when even more folders were added to node_modules.This is happening here in Travis too, I think the crux of the issue is it’s watching
/static
. Even if it has to runchokidar
inbuild
mode, if we could pass a watch ignore pattern, we could ignore folders likestatic
. Unless doing so would prevent it from copying to build? 🤔 UsingCHOKIDAR_USEPOLLING=1
seems to help.What if I deploy to netlify and encounter that error when netlify tries to build the app? On local it’s fine
Instead of allowing Webpack to watch half a million files in node_modules (which you are never going to change), you can tell it ignore certain directories, like node_modules: https://webpack.js.org/configuration/watch/#watchoptionsignored
Alternative solution for vscode:
Instead of increasing limits you could also add
public
and.cache
folders tofiles.watcherExclude
or
via https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc
I followed the ‘fix’ to set max watchers to 524288, rebooting, none of it fixed the issue. I’m sure it helped, but I was still experiencing this issue.
I added the environment variable using:
export CHOKIDAR_USEPOLLING=1
And that helped. I was able to run
gatsby develop
on my site.Please just add a reaction to the solution that worked for you, rather than making a new comment that just says “worked for me”.
I still get this occasionally on Netlify with
gatsby build
, even through my project is fairly small. It’s difficult to debug, because it doesn’t occur every time. Clearing the cache & redeploying will fix it, but also, just a normal re-deploy will often work.There’s no
sudo
access during netlify builds, so changing the system limit isn’t an option. Also, manually re-deploying isn’t a real “solution” - I have client websites that rebuild after CMS changes, and I don’t want to be ‘on call’ to click the ‘redeploy + clear cache’ button whenever this happens.Is there a way to see and/or limit what files are being watched? I don’t know much about how Gatsby works under the hood, but, assuming that gatsby watches files in order to re-build while developing, does
gatsby build
really need to be watching anything in the first place?I’m getting this error on Netlify. Anyone know how to fix it?
Restarting my computer fixed the issue.
If you are getting this error because you are working on a REACT/STRAPI or NODE or something related to javascript and react vis Ubuntu then below will help you.
run this on your terminal
sudo gedit /etc/sysctl.conf
Add a line at the bottom
fs.inotify.max_user_watches=524288
Then save and exit!
sudo sysctl -p
to check it
Then it is solved!
go back to your VS-CODE or any IDE you are using and run your code again
Thanks 😄
got the same issue: solved with: increasing users. echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Following is the best solution. Hit the command - echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
There is a shortcut to setting this parameter. This accomplishes the same thing as the top voted answer:
Gracias crack, leyenda, titán!
Try
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p``Thank You so much!!!
Thanks, solved
This worked for me
Thanks! It the computer’s way of saying “restart me”
I just had to close Visual Studio Code and that solved the problem.
delete react node_modules
if error occurs use this method again
Hello! Any updates on this issue? I encounter this occasionally when building my gatsby site in Jenkins. I don’t have permissions to the modify the inotify max_user_watches in my Jenkins build environment.
Using the
sysctl -p
approach after settingfs.inotify.max_user_watches
did not work for me , either. (by the way this setting was already set to a high value, likely from me trying to fix this issue a while back ago).The best solution to the problem I found here:
sysctl fs.inotify.{max_queued_events,max_user_instances,max_user_watches}
and then set it to a different value (a lower value may do it)sudo sysctl -w fs.inotify.max_user_watches=16384
kill
the process you found in (1) that consumes the most file watchers (in my case,baloo_file
)balooctl disable
.Now run
sudo code --user-data-dir
and it should open vscode with admin privileges this time. (by the way when it does not runsudo code --user-data-dir --verbose
to see what the problem is - that’s how I figured out it had to do with file watchers limit).yes … thanks indeed Aleks for the kind attention to this.
I’ll close it out…
very best ! cheers.
John D Allen.
T +1 417 849 0705 ** CST | @.** @.***> | https://www.leveridgesystems.com https://www.leveridgesystems.com | linkedin.com/in/johndallen1 http://linkedin.com/in/johndallen1 | skype john.allen_67 *
Leveridge Systems INC. Reg Missouri Charter #01082460. The information contained in this email and any attached files is confidential and intended solely for the addressee(s). The email may be legally privileged or prohibited from disclosure and unauthorized use. If you are not the named addressee you may not use, copy, or disclose this information to any other person. If you received this message in error please notify the sender immediately and permanently delete it from your system.
On Sat, Mar 20, 2021 at 4:29 AM Aleksandar Gocanin @.***> wrote:
If anyone was curious about the numbers and overhead, I ended up looking into it a bit rather than just copying what appears like random numbers online and hoping for the best 😛
The
524288
mentioned here and some other places from theguard/listen
wiki (seems to be original source?), is 2^19 (exponent, as in 2x2x2x2…19 times), where each watch(only when actually used) requires 1,080 bytes of memory, meaning you would use 540MiB of RAM if you managed to use all those, just for the file watchers.There’s also this handy script, which can tell you where all the watchers are allocated to presently. In my case I had been using a
max_user_watches
of 2^16 (65536) and two electron processes(VS Code) had 24-28k watches each active, a few others had a few thousand each, and minor watches for everything else.@x0xl0ma in future just add a 👍 to the comment that helped you, if your comment doesn’t provide any value for others due to being a thankyou (🎉) or repeating confirmation, it just adds noise that others have to wade through (notice that Github hides 30+ comments on this thread as an optimization, that can hide good/useful information that might be missed in a sea of “thanks” and “works”.
Thanks,
save my day, thanks!!
@ethannkschneider I was running into this problem when building in a restrictive Jenkins environment as well. Using
CHOKIDAR_USEPOLLING=1
avoids hitting the watched limit for me.I’m currently working on this. @sidharthachatterjee I’m unable to assign or add labels. Thanks for your help!
worked too. thanks
Yes It is working