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)

Commits related to this issue

Most upvoted comments

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.

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

thank you very much!!!

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

I 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:

  • su
  • enter your password
  • npm run serve

Noooooooo don’t run your app as root! 💀 🚨 That can cause all kinds of security problems!

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

thanks. it’s really helpfull

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

it saved my day

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

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

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

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?

8:10:54 AM: error watch /opt/build/repo/gatsby-config.js ENOSPC
8:10:54 AM: UNHANDLED EXCEPTION watch /opt/build/repo/gatsby-config.js ENOSPC
8:10:54 AM: See our docs page for more info on this error: https://gatsby.dev/issue-how-to
8:10:54 AM: 
8:10:54 AM:   Error: watch /opt/build/repo/gatsby-config.js ENOSPC
8:10:54 AM:   
8:10:54 AM:   - nodefs-handler.js:38 createFsWatchInstance
8:10:54 AM:     [repo]/[chokidar]/lib/nodefs-handler.js:38:15
8:10:54 AM:   
8:10:54 AM:   - nodefs-handler.js:81 setFsWatchListener
8:10:54 AM:     [repo]/[chokidar]/lib/nodefs-handler.js:81:15
8:10:54 AM:   
8:10:54 AM:   - nodefs-handler.js:233 FSWatcher.NodeFsHandler._watchWithNodeFs
8:10:54 AM:     [repo]/[chokidar]/lib/nodefs-handler.js:233:14
8:10:54 AM:   
8:10:54 AM:   - nodefs-handler.js:262 FSWatcher.NodeFsHandler._handleFile
8:10:54 AM:     [repo]/[chokidar]/lib/nodefs-handler.js:262:21
8:10:54 AM:   
8:10:54 AM:   - nodefs-handler.js:495 FSWatcher.<anonymous>
8:10:54 AM:     [repo]/[chokidar]/lib/nodefs-handler.js:495:21
8:10:54 AM:   

I got it today too and did a “clear cache and redeploy” and it worked.

Alternative solution for vscode:

Instead of increasing limits you could also add public and .cache folders to files.watcherExclude

"files.watcherExclude": {
    "**/public/**": true,
    "**/.cache/**": true
}

or

image

via https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc

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 run chokidar in build mode, if we could pass a watch ignore pattern, we could ignore folders like static. Unless doing so would prevent it from copying to build? 🤔 Using CHOKIDAR_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 to files.watcherExclude

"files.watcherExclude": {
    "**/public/**": true,
    "**/.cache/**": true
}

or

image

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

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

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:

sudo sysctl fs.inotify.max_user_watches=524288

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

Gracias crack, leyenda, titán!

ENOSPC = Erro NO Seu PC @Victorcorcos

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

Thank You so much!!!

Thanks, solved

Está atingindo o limite de observadores de arquivos do seu sistema Tentar echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p Leia mais sobre o que está acontecendo em https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers#the-technical-details

Muito obrigado!!!

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

This worked for me

Alright I restarted the computer, and now everything works fine again.

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

rm -r node_modules

yarn or npm install

yarn start or npm start

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.

Error: ENOSPC: System limit for number of file watchers reached,

I am having this issue

Tried echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p but didn’t work for me.

Using the sysctl -p approach after setting fs.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:

  1. Use this script to identify which processes are requiring the most file watchers in your session.
  2. You can then query the current max_user_watches value with 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
  3. Or you can simply kill the process you found in (1) that consumes the most file watchers (in my case, baloo_file)
  4. The above, however, will likely need to be done again when restarting the system - the process we identified as responsible for taking much of the file watchers will (in my case - baloo_file) - will again so the same in the next boot. So to permanently fix the issue - either disable or remove this service/package. I disabled it: 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 run sudo 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:

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

Works for me. Thank you 😄

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/gatsbyjs/gatsby/issues/11406#issuecomment-803278827, or unsubscribe https://github.com/notifications/unsubscribe-auth/ADGDUXO3C6XAMVBYPBTPNILTERTGLANCNFSM4GTE6GVA .

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 the guard/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”.

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

Thanks,

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

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!

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

worked too. thanks

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

Yes It is working