gatsbyjs / gatsby

The best React-based framework with performance, scalability and security built in.
https://www.gatsbyjs.com
MIT License
55.19k stars 10.33k forks source link

Error: ENOSPC: System limit for number of file watchers reached, watch '/home/foldername/abcrypto/static' #11406

Closed omrllm closed 4 years ago

omrllm commented 5 years ago

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
sidharthachatterjee commented 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

omrllm commented 5 years ago

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

YamadaKY commented 5 years ago

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

isaacjamesdev commented 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

thank you very much!!!

jtlindsey commented 5 years ago

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

QasimRRizvi commented 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

it saved my day

chrisobo98 commented 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

I ran this line of code in a react-app and everything went back to normal again, thanks!!

algol007 commented 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

thanks. it's really helpfull

ravikirany711 commented 5 years ago

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

Thanks man , you are a hero

cedricdelpoux commented 5 years ago

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

hoummani commented 5 years ago

Serve your app as root.....It's work!

cedricdelpoux commented 5 years ago

Serve your app as root.....It's work!

Could you explain ?

hoummani commented 5 years ago

Run sudo npm run serve inside you app folder or run this commands as below:

jessepinho commented 5 years ago

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

dtran26 commented 5 years ago

What if I deploy to netlify and encounter that error when netlify tries to build the app? On local it's fine

himharsh1997 commented 5 years ago

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

Yes It is working

i-bsd commented 5 years ago

I'm getting this error on Netlify. Anyone know how to fix it?

meronek commented 5 years ago

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

wahabAwudu commented 5 years ago

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

worked too. thanks

sidharthachatterjee commented 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

Reopening this since it looks the above is a popular answer and that this issue is prevalent enough to warrant better resources/warnings on

We should do two things for now:

eduarmreyes commented 5 years ago

@sidharthachatterjee where exactly do you see this quoted in the documentation, what page? :thinking:

KirankumarAmbati commented 5 years ago

@sidharthachatterjee, is this taken ? If not, I can take it up, but definitely need your help. :D

sidharthachatterjee commented 5 years ago

@eduarmreyes That's a very good question! Perhaps a new page linked to in https://www.gatsbyjs.org/docs/debugging/

@KirankumarAmbati If @eduarmreyes is taking up the documentation you could try out the second point in the list! Happy to help 🙂

asasmith commented 5 years ago

I'm currently working on this. @sidharthachatterjee I'm unable to assign or add labels. Thanks for your help!

good-idea commented 5 years ago

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?

mkreutner commented 5 years ago

It's work fine for me ! Thanks very much !

antoinerousseau commented 5 years ago

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:   
fahadtufail1 commented 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

Thanks man! it saved my time :raised_hands:

Tset-Noitamotua commented 5 years ago

it still happens ... with the quick start guide :eyes:

image

jessepinho commented 4 years ago

Note that @pieh answered the question of "why do files need to be watched while building for production?" over in #15843:

Because used package for globbing + watching (chokidar) doesn't have way to disable watching. We were looking for alternatives, but there were none that actually allow to disable watching. We could use different packages for builds (so only globbing, without watching) and develop (globbing + watching) - but this introduce potential to cause differences between builds and develop

Looks like this issue should be taken up with chokidar first to add a watch option, then a followup issue created for Gatsby to implement the watch option.

Elya29 commented 4 years ago

thank you so much!! It worked for me :D

jessepinho commented 4 years ago

Also, chokidar isn't going to add an option to disable watching, since it's literally a file watcher. The only possible solution I can think of would be for Gatsby to switch to a different library for traversing directories that allows both watch and non-watch options.

ghost commented 4 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

Dang Sid beat me to the punch i was ganna say this yea it has to do with (Im assuming your on linux) how linux has there default setup of file watchers its an easy fix just by running that command in terminal or you can go here https://code.visualstudio.com/docs/setup/linux#_visual-studio-code-is-unable-to-watch-for-file-changes-in-this-large-workspace-error-enospc on VS Code website they have a whole section on it teaching you how to solve this issue

gatsbot[bot] commented 4 years ago

Hiya!

This issue has gone quiet. Spooky quiet. 👻

We get a lot of issues, so we currently close issues after 30 days of inactivity. It’s been at least 20 days since the last update here.

If we missed this issue or if you want to keep it open, please reply here. You can also add the label "not stale" to keep this issue open!

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks for being a part of the Gatsby community! 💪💜

ethannkschneider commented 4 years ago

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.

Fthi-S3074641 commented 4 years ago

https://github.com/gatsbyjs/gatsby/issues/11406#issuecomment-458769756

gatsbot[bot] commented 4 years ago

Hey again!

It’s been 30 days since anything happened on this issue, so our friendly neighborhood robot (that’s me!) is going to close it.

Please keep in mind that I’m only a robot, so if I’ve closed this issue in error, I’m HUMAN_EMOTION_SORRY. Please feel free to reopen this issue or create a new one if you need anything else.

As a friendly reminder: the best way to see this issue, or any other, fixed is to open a Pull Request. Check out gatsby.dev/contribute for more information about opening PRs, triaging issues, and contributing!

Thanks again for being part of the Gatsby community!

jessepinho commented 4 years ago

cc https://github.com/gatsbyjs/gatsby/issues/15843#issuecomment-554281918

esturcke commented 4 years ago

@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.

AmShubhangi commented 4 years ago

Following is the best solution. Hit the command - echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

angelocdz commented 4 years ago

delete react node_modules

rm -r node_modules

yarn or npm install

yarn start or npm start

if error occurs use this method again

sandroweb commented 4 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

Tks!!!

irokhes commented 4 years ago

@cedricdelpoux did you solve this error?

Give me the error: sysctl: illegal option -- p

Using on MacOS

ahsan-khan1999 commented 4 years ago

got the same issue: solved with: increasing users. echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p

juanvs23 commented 4 years ago

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

Is work!!

Zeebrommer commented 4 years ago

@irokhes sysctl -p is used to reload the changed config from /etc/sysctl.conf on Linux. You will have to find out how to change sysctl.conf (probably located somewhere else) on Mac. Then you can change the fs.inotify.max_user_watches-property (if it is called the same on Mac).

DannyFeliz commented 4 years ago

I just had to close Visual Studio Code and that solved the problem.

brunonepomuceno commented 4 years ago

If you are not interested in the technical details and only want to get Listen to work:

If you are running Debian, RedHat, or another similar Linux distribution, run the following in a terminal:

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

If you are running ArchLinux, run the following command instead (see here for why):

echo fs.inotify.max_user_watches=524288 | sudo tee /etc/sysctl.d/40-max-user-watches.conf && sudo sysctl --system

Then paste it in your terminal and press on enter to run it.

More info: https://github.com/guard/listen/wiki/Increasing-the-amount-of-inotify-watchers

barhoring commented 4 years ago

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

Thanks! It the computer's way of saying "restart me"

kamranayub commented 4 years ago

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.