Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Error watching file for changes: EMFILE #76

Open
tinovyatkin opened this issue Feb 6, 2017 · 10 comments
Open

Error: Error watching file for changes: EMFILE #76

tinovyatkin opened this issue Feb 6, 2017 · 10 comments

Comments

@tinovyatkin
Copy link

Hello,
Extension shows error at output:

screen shot 2017-02-06 at 17 52 07 pm

pure node --harmony project, no babel anywhere, npm test = node --harmony node_modules/.bin/jest

@orta
Copy link
Member

orta commented Feb 7, 2017

Hrm, that's worrying, that's coming Jest directly - could you not have watchman installed?

@tinovyatkin
Copy link
Author

@orta yep, installing watchman solves that! I didn't realise it's a dependency, that's nowhere mentioned... Thank you!

@orta
Copy link
Member

orta commented Feb 16, 2017

👍 interesting, I would have thought watchman was an optional dep

@t-kelly
Copy link

t-kelly commented Mar 18, 2018

Have also come across this issue. Care to explain what's causing it? Not familiar with watchman...

@seanpoulter
Copy link
Member

@tinovyatkin & @orta, remember what's up with this one?

@orta
Copy link
Member

orta commented Mar 18, 2018

watchman is what powers the jest file watcher, it's not optional - https://github.com/facebook/watchman

Someone could send a PR that adds a verification for it being installed

@bdarnell
Copy link

bdarnell commented Aug 8, 2019

I see a similar error (but not exactly the same). When run in vscode with this extension, the tests run (and pass), and then it fails to enter watch mode with

2019-08-08 16:32 node[24048] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

2019-08-08 16:32 node[24048] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

2019-08-08 16:32 node[24048] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:123:28)

2019-08-08 16:32 node[24051] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

2019-08-08 16:32 node[24051] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

2019-08-08 16:32 node[24051] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:123:28)

2019-08-08 16:32 node[24054] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

2019-08-08 16:32 node[24054] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

2019-08-08 16:32 node[24054] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:123:28)

2019-08-08 16:32 node[24057] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

2019-08-08 16:32 node[24057] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

2019-08-08 16:32 node[24057] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:123:28)

2019-08-08 16:32 node[24060] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

2019-08-08 16:32 node[24060] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

2019-08-08 16:32 node[24060] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)

Error: EMFILE: too many open files, watch
    at FSEvent.FSWatcher._handle.onchange (internal/fs/watchers.js:123:28)

Starting Jest in Watch mode failed too many times and has been stopped.
 see troubleshooting: https://github.com/jest-community/vscode-jest/blob/master/README.md#troubleshooting

I did not have watchman installed at first (although i did have fb-watchman, which seems to have replaced watchman for newer versions of jest). Installing watchman and restarting everything did not help.

I used the debug option to log the command being run, it's yarn test --testLocationInResults --json --useStderr --watch --no-color. I can run this in a terminal with no problem (both a standalone terminal and vscode's built-in terminal).

Everything used to work in this repo with the vscode extension; the problems started when I deleted my node_modules directory and reinstalled everything. No idea what might have changed there.

@bdarnell
Copy link

bdarnell commented Aug 8, 2019

FWIW, if I set "path to jest" to yarn test -- --no-watchman it works (including watch mode).

@ntwb
Copy link

ntwb commented Dec 29, 2019

Looks like I've solved this for myself, for now, after reading many of the conflicting reports that watchman or fb-watchman being installed, or not installed I've not touched any of that for fear of perpetuating that side of things.

Anyways, I had tried removing node_modules and reinstalling, that worked once or twice, I restarted the Finder app, because, open files, again this issue kept reappearing

Next I thought that Jest was trying to watch all the files in /node_modules, wondering if like much of these tools they will inherit the ignore path from the .gitignore, went looking at the docs and no mention of Jest doing that.

Side Note: I believe testPathIgnorePatterns ignores /node_modules by default

Thus I tried adding /node_modules to watchPathIgnorePatterns

Yup, this now works for me, consistently, with this not set Jest fails to start in watch mode, setting this Jest will start and restart in watch mode successfully

"jest": {
	"watchPathIgnorePatterns": [
		"/node_modules/"
	]
}

The above is in my package.json file, I'll try updating it in some Jest config files and shared configs a bit later

There's a few Jest issues that state the above works as a workaround but not the ideal solution, it was supposedly fixed in Jest 24.8.0, but not for everyone and the above workaround is still required

So whilst the above works, the consensus appears to be that this is not the "right" solution, if you've complex projects this wouldn't be ideal, so for now, this will work for me and I'll keep an eye on the above linked Jest issue

@itaisir
Copy link

itaisir commented Nov 30, 2020

The easiest thing would be to install Watchman:

$ brew update
$ brew install watchman

If you don't have brew, do this first:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

romaricpascal added a commit to alphagov/govuk-design-system that referenced this issue Aug 2, 2024
Running `npx jest --watch` threw EMFILE errors in the console, for which [ignoring `node_modules` is a workaround](jest-community/vscode-jest#76 (comment)).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants