jestjs/jest

Watch mode stopped working on macOS Sierra

Anahkiasen opened this issue Β· 140 comments

This is a bug that seems to happen ever since I've updated to Sierra.

Whenever I want to run Jest in --watch mode it crashes:

$ jest --watch
2016-09-22 10:49 node[79167] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2016-09-22 10:49 node[79167] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2016-09-22 10:49 node[79167] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error watching file for changes: EMFILE
    at exports._errnoException (util.js:1036:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1406:11)

Tried reinstalling the node modules, checking for any updates and anything. I can't seem to reproduce it on a new project but on the other hand even if I just run an empty test suite with --testPathPattern it still crashes, so I'm guessing it's a dependency conflict somewhere. I don't have any setup files or anything, it's literally running an empty file and crashing.

I don't get any more output with --debug so not sure what else to provide to help. This does not happen with --watchman

$ node --version && npm --version && jest --version
v6.6.0
3.10.8
v15.1.1

I had the same issue. Upgrading watchman with brew install watchman to v4.7.0 fixed it.

I'm quite confident this is not a Jest issue but either an underlying module or something else on your system. Unsure how to troubleshoot, everything is fine here on Sierra.

I also got a similar report about Sierra: facebook/create-react-app#713

@cpojer Do you have a Sierra? Have you tried 6.6.0 on it?

Per facebook/create-react-app#713 (comment), uninstalling Watchman fixes the issue so it’s either a problem with Watchman, or its Jest integration on Sierra.

A few other possibly related threads:

ember-cli/ember-cli#6259
facebook/watchman#358

Can you try any suggestions there and report back?

@gaearon I'm using node 6.6.0 on Sierra with watchman and everything is fine.

Definitely seems like a watchman/upgrading issue. I'm gonna close this out for now but happy to reopen in case this is actually a Jest problem. Since many people reported this on other projects (rn) it is unlikely though.

gnoff commented

I do not believe I have ever had watchman installed and I just now am experiencing this issue with jest in watch mode. I also recently upgraded to macOS Sierra. My guess is watchman can help (and I will try it as a workaround) but I don't think the problem is native to having or using watchman

FWIW I don't have watchman installed and still had this bug, but deleting my node_modules folder and reinstall did the trick for me

I think it is a bit short through the corner to close this issue. Jest reports an error, so maybe the problem is in one of the dependencies which need to be updated? I removed my node_modules and reinstalled, but to no avail. I never installed watchman and even if I did, the dependencies should be coming from my package.json, not from any external program I installed.

I was thinking that fsevents is the issue. I would recommend reinstalling the node binary, wiping away all node_modules folders and doing a fresh npm install.

I installed new node binary (6.7.0), removed node_modules again, reinstalled everything but still the same error. But I guess the problem is that it is trying to watch too many files at once: http://stackoverflow.com/questions/8965606/node-and-error-emfile-too-many-open-files

The folks over on react-native fixed the too many files at once issue I think here

However for me, it was still an upgrade of watchman that fixed it.

Usually when this happens it is a sign to restart the computer. This happens frequently at FB too (unrelated to Jest) :(

Sorry to be such a pain in the *ss. I raised the ulimits as pointed out in the issue @robzolkos pointed at, but why would I need to install watchman? It is not a dependency of Jest, I just use Jest out of the box as is. This is my setup now:

14:31 $ ulimit -n
100000
14:31 $ node --version
v6.7.0
14:31 $ npm -v
3.10.3

The project contains about 45k files (including node_modules) so I don't see why it could still give me an EMFILE. I will check if installing watchman is a workaround.

@hmeerlo watchman is a file watching service built by FB to make file system operations faster. Jest will run much faster on a big repo if watchman is installed and it brings the startup overhead of Jest to practically nothing as it will only statically analyze files that have changed.

Thanx, I just checked it and it works flawless now, but there still is another issue somewhere for people who do not have watchman installed, as it is not a requirement for jest.

It's not a strict requirement but just like react-native, on big repositories with large dependency trees (lots of node modules, for example), we do recommend watchman for better performance and to avoid the problems mentioned in this issue. I would recommend your team to install it to speed up common file system operations.

@cpojer Should we document Watchman in CRA User Guide?

@gaearon Yeah, I don't think there is any problem with that. I would recommend adding it to the Jest docs as well.

I'm unsure how big the dependency tree of cra's node_modules is. If it is sufficiently large we should probably recommend watchman to most people.

FYI Even though reinstall all node_modules initially did the trick for me, seems it was temporary, borked again. But installing watchman resolved this for me.

+1 to documenting it in Jest as a recommended install.

It's unclear what the outcome of this issue is. Just now I've freshly installed Jest (with fresh node_modules) on Sierra and run into this problem, which makes --watch unusable. Is that the resolution of this issue just that Jest's watch mode does not work on Sierra? Or it only works on Node 6 with Watchman?

Do you have problems if you uninstall Watchman completely? Jets should use the Node based watcher if you do so. Do you have issues with it as well?

@gaearon I only got it to work by installing Watchman. Without Watchman, no luck.

Same here, it's without watchman that it doesn't work for me

I was having this problem using node 4.6.0 after upgrading to Sierra. After upgrading node to v6.7.0, clearing node_modules and running a new npm install, jest watch started working again. I had to both upgrade node and then clear node_modules, though; those things individually didn't fix the problem.

Mac OS Sierra (10.12.1). Node 6.7. If I don't install watchman, I get the error. Please reopen. This is a jest problem, and also creates problems when using create-react-app.

Same for me with Sierra. Installing watchman resolved the issue, but before that (and I had tried everything), I got the above error. I kept avoiding the watchman-related fixes because I had never installed it in the first place.

I'm reopening because we get reports about this in Create React App with uninstalling Watchman fixing the issue. Therefore the problem is in whatever Jest uses when Watchman is disabled.

Whether or not this is a Watchman issue, it affects Jest users, and by proxy, all Create React App users. Create React App chose Jest as a runner in the hope that such issues are addressed, whether in Jest, Watchman, or any other underlying projects.

No matter whose fault this issue is, I don't think we can close it until we have clear instructions about how to fix it, and I can tell something consistent about fixing it to Create React App users.

I can't tell something as vague as "Try installing, or maybe uninstalling Watchman, whatever works" to people if tests literally don't run inside newly created projects. If some versions of Watchman are buggy or incompatible, Jest should bail out of using them. If Node crawler is buggy, Jest should fix it, or force users to install Watchman.

Just thought I'd pop in and say I'm having this same issue while using Jest through create-react-app. With watchman installed, the test runner hangs indefinitely, and without it I get the same error as the OP.

I'm running macOS 10.12.1 with the following version of my dependencies:

β–Έ node --version; and npm --version; and create-react-app --version; and watchman --version; and npm ls jest
v7.0.0
3.10.8
create-react-app version: 0.6.0
4.7.0
Todo@0.1.0 /Users/rpowell/Code/react-todo
└─┬ react-scripts@0.7.0
  └── jest@16.0.2 

Hey everyone,

I've been incredibly busy with a bunch of projects and was unable to spend any time on this issue. I'm sorry about that. There have a been a ton of reports here and different solutions seem to have worked for different people. I'd like to figure out what is going wrong and how to fix it, however I have not been able to reproduce this issue and it doesn't seem like there are any repro steps available in this thread either. Can somebody who ran into this spend some time trying to figure out a consistent repro that I can test locally?

My home iMac isn't experiencing these issues, so I'll see if I can repro it there.

@cpojer Just tested it, merely removing the watchman binary triggered the issue for me again. Besides that my gut feeling is that the size of the project matters.

I have the same problem & I tried all the solutions, none of them worked for me:

  • Delete node_modules/
  • Install watchman
  • Uninstall watchman
$ node -v && npm -v && jest --version
v6.1.0
3.8.6
v16.0.2

Yep, same for me guys installing watchman fixed it for me, thanks for all your help guys

h9h commented

I've started experiencing the problem right now too. Was working on a project yesterday on macOS, worked fine. Today worked on same project under windows 7, worked fine. Came home pulled the project onto macOS, failed. Will see tomorrow if it still works on windows.

Size of project has increased since yesterday.

$ node -v && npm -v && jest --version
v6.2.0
3.8.9
v16.0.2

Tried installing watchman. Failed - got the message outdated Xcode (8.0). Installed 8.1. Installed watchman. Install Succeeded.
After that the tests were running again.

I started seeing this issue after upgrading to macOS Sierra, I resolved it by installing watchman

Error

Determining test suites to run...2016-11-04 12:51 node[4311] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2016-11-04 12:51 node[4311] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2016-11-04 12:51 node[4311] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error watching file for changes: EMFILE
    at exports._errnoException (util.js:1026:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1406:11)
npm ERR! Test failed.  See above for more details.

Environment

node v6.9.1
jest v16.0.2
npm v3.10.9

Unsuccessful steps

  • npm rebuild
  • rm -rf node_modules && yarn

Edit
My project is a forked Create React App project and it still pretty small.

Confirmed on Serria it's due to watchman not being installedbrew install watchman fixed it for me

Reportedly, this may fix the issue:

launchctl unload -F ~/Library/LaunchAgents/com.github.facebook.watchman.plist
watchman version

JFYI I have such problem with watchman when I run jest --watch from inside tmux.

It works like a charm outside.

One more twist on this (in a create_react_app): deleting node_modules and reinstalling with yarn install did not help. Deleting node_modules and reinstalling with npm install DID resolve the issue for me. So this issue is somehow related to number of packages and/or how yarn installs packages.

@stefaneg the problem is related to the maximum number of open files. yarn install probably results in more files therefore you run into the maximum number of files limit whereas npm install probably just stays under this limit.

launchctl unload ~/Library/LaunchAgents/com.github.facebook.watchman.plist fixed it for me

FWIW, I was getting this exact error on:

mocOS: 10.12.1
Node: 6.6.0
NPM: 3.10.3
Jest: 10.0.1

I installed watchman (via homebrew) and it resolved the error.

Bonus FWIW: Jest is awesome. So glad I gave it a second chance :)

To add more entertainment value to this. I was running into the error, inside of tmux. Tried the suggestion of running outside, and it worked, went back inside of tmux and it worked.

macOS: 10.12.1
Node: 6.9.1
yarn: 0.17.3
Jest: 17.0.2
watchman: 4.7.0

hbd commented

Can confirm that this issue was related to tmux. After getting the error

2016-11-04 12:51 node[4311] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2016-11-04 12:51 node[4311] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error watching file for changes: EMFILE
    at exports._errnoException (util.js:1026:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1406:11)
npm ERR! Test failed.  See above for more details.

from running react-native commands, I installed watchman, but continued to get the issue. Running react-native commands outside of tmux now works. I do not have jest installed.

I was getting not using tmux, only iterm2..

Had the same issue on two other repos but not on another all using the same versions. Which is odd. So it might have to do with the amount of files?

macOS: 10.12.1
node: 6.9.1
npm: 3.10.8
jest: 17.0.3

using nvm for node version control

npm command is
"test:watch": "cross-env NODE_ENV=test jest --watchAll",

Tried reinstalling node_modules did not fix it.

Installing watchman fixed the issue for me.

brew install watchman

watchman: 4.7.0

Confirming the same issue. Installing watchman fixed the problem.

It seems like most people resolves this issue in one way or another and it most likely had to do with issues around OS upgrades, node modules, watchman and node. We never had a repro at FB, so it is hard to know what exactly was going on here. I'll close it as non-actionable at this point. If you are reading this in the future, please scroll up and try any of the solutions people brought up.

I also summarized a few workarounds here.

MoOx commented

I got this issue with a new laptop, I just installed node + my project + yarn install + jest --watch and got the issue. I had to install watchman to "fix" this. Maybe it's related to the fact that yarn does not link all node_modules/.bin of submodules like npm does?

I had jest running on other projects fine, though ran in to this issue with an immediately ejected create-react-app.
brew install watchman fixed it though.

@MoOx Unfortunately at this point I don’t think we’ll figure out the root until somebody who has the issue takes the time to figure out what is happening (e.g. you could put console logs in Jest sources and its Node-based watcher).

MoOx commented

Actually I can reproduce as soon as I uninstall watchman. Can somebody point me to the right direction so I can add some logs and paste those here?

I think that without watchman Jest falls back to Node crawler. Something in Sierra might've broken it. So maybe worth putting some logs there.

Same thing here:

$ yarn test
yarn test v0.17.0
$ react-scripts test --env=jsdom
Determining test suites to run...2017-01-04 09:58 node[9151] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-01-04 09:58 node[9151] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-01-04 09:58 node[9151] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error watching file for changes: EMFILE
    at exports._errnoException (util.js:1036:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1406:11)
error Command failed with exit code 1.
  • iterm2: 3.0.13
  • macOS: 10.12.1 (Sierra)
  • nvm: 0.31.0
  • node: v6.7.0
  • npm: 3.10.3
  • yarn: 0.17.0
  • jest: 16.0.2

Installing watchman fixed it for me.

Another data point: I just had this issue on Node 6.9.1, switching to 6.3.1 solved it.

Bummer that this is closed, having to dig through issues in upstream projects does make for a poor initial experience with create-react-app as noted here #1767 (comment)

As I noted above, please feel free to dig into why this happens. While this is inconvenient, this is an open source project, and you can help us. Right now I have a lot of work on React itself and unfortunately don’t have time to look into why this happens. It seems like usually it’s fixable by installing (or uninstalling) watchman so, while irritating, people tend to work around it quickly.

I will try to take a look at it and see if I can figure anything out. It definitely feels like the issue is coming from sane and may be related to this nodejs/node-v0.x-archive#5463

@gaearon installing watchman resolved the issue for me. Thanks!

I decided to research this, as I didn't want to make people install watchman.

The error seems to be thrown by walker when it searches too many files/directories using fs.lstat. You can pass a predicate function that will ignore certain folders. (Ignoring node_modules solves the issue.)

However, walker is called by sane which doesn't have the ability to pass the ignore function. (They have recently added an ignore option, but it doesn't seem to work with nodejs-walker)

It appears a PR will need to be made to update sane to accept an ignore function and then a PR to jest to pass that to sane, and create a function based on that jest ignores. Add it in jest-haste-map here

@ro-savage thank you so much for doing this investigation. Would you be open to make a change to sane? I'm also happy to switch off of sane if you'd like to write a file-watching system directly within this repo, but that is probably a bigger challenge.

@cpojer - Already in the works. Once the changes to sane have been merged and released, I'll make a PR for jest.

That's awesome. Looking forward to it.

Something to keep in mind: it would be nice if we ignored specifically the root node_modules rather than /node_modules/ generally. See #2796 and #2318 for some context for why I’d like src/node_modules to still be working.

Also,

The error seems to be thrown by walker when it searches too many files/directories using fs.lstat. You can pass a predicate function that will ignore certain folders. (Ignoring node_modules solves the issue.)

sounds more like a workaround than a solution. I would like to better understand this. Yes, ignoring node_modules works around the problem because there is less files. But presumably on a large enough project you could hit this limit too. Is there a way to fix the underlying problem (β€œerror seems to be thrown by walker when it searches too many files/directories”)?

First comment wasn't quiet clear.

The root issue isn't actually an issue with walker that works fine.
The issue is MacOS Serria + Node, how it executes fs.watch. As discussed here nodejs/node-v0.x-archive#5463
I didn't dive too deep into that, but looks like it was never fixed or possibly isn't a node issue.

Instead the fix allows walker to crawl all the directories (which is fast + works fine), it then removes everything that matches the predicate function, and sane will only attempt to attach watchers to files that aren't in the ignore.

@gaearon sane is using anymatch to decide what to ignore, which accepts regex. Therefore CRA can update its jest ignore with something that will only match node_modules at the root level.

I can in fact confirm as others have that brew install watchman works. Dang tho it'd be cool not to have to now add that step to my project's README. :-D. If there's anything I can do to help test or anything, let me know!

I have submitted PR #2957 that should fix this issue without installing watchman.

Would love for people to try it out and confirm it fixes on their systems as well. @jcreamer898 @mulchy @MoOx

Steps to test:
brew uninstall watchman
git clone https://github.com/ro-savage/jest.git
git checkout fix-watcher-bug-osx
yarn install
yarn build
cd packages/jest-cli
yarn link

Then go to your project that you had crashing tests in a run
yarn link "jest-cli"

Make sure you have testPathIgnorePatterns config set to includenode_modules
Run your tests as usual.

Once you're done. run yarn unlink jest-cli in the project folder to go back to your regular jest.

Does this only fix crashing tests, or hanging tests too? Most commonly I just observed Jest hanging on "Determining test cases to run..."

I have never had jest hanging on Determining test cases to run.... So unless it's by accident, it doesn't fix that issue

The issue hits me too.
brew install watchman solved it.

@ro-savage thanks for doing this! I attempted to test this, but I think I am slightly confused by the configuration. I cloned your project and built the new jest-cli package and linked it. Then I went to the existing failing project and did the following:

Ξ» jakku pokedex-client β†’ Ξ» git master* β†’ rm -rf node_modules
Ξ» jakku pokedex-client β†’ Ξ» git master* β†’ yarn install
yarn install v0.19.1
[1/4] πŸ”  Resolving packages...
[2/4] 🚚  Fetching packages...
[3/4] πŸ”—  Linking dependencies...
[4/4] πŸ“ƒ  Building fresh packages...
✨  Done in 122.29s.
Ξ» jakku pokedex-client β†’ Ξ» git master* β†’ yarn link "jest-cli"
yarn link v0.19.1
success Registered "jest-cli".
✨  Done in 0.26s.
Ξ» jakku pokedex-client β†’ Ξ» git master* β†’ yarn test
yarn test v0.19.1
$ react-scripts test --env=jsdom
2017-03-03 10:30 node[4640] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-03-03 10:30 node[4640] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-03-03 10:30 node[4640] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-03-03 10:30 node[4640] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-03-03 10:30 node[4640] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-03-03 10:30 node[4640] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-03-03 10:30 node[4640] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-03-03 10:30 node[4640] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-03-03 10:30 node[4640] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error watching file for changes: EMFILE
    at exports._errnoException (util.js:1022:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1406:11)
error Command failed with exit code 1.

My package.json looks like this:

{
  "name": "pokedex",
  "version": "0.1.0",
  "private": true,
  "devDependencies": {
    "react-scripts": "0.8.5",
    "redux-devtools": "^3.3.2"
  },
  "dependencies": {
    "react": "^15.4.2",
    "react-dom": "^15.4.2",
    "react-redux": "^5.0.2",
    "react-router": "^3.0.2",
    "redux": "^3.6.0"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test --env=jsdom",
    "eject": "react-scripts eject"
  },
  "proxy": "http://localhost:3000",
  "jest": {
    "modulePathIgnorePatterns" : ["<rootDir>/node_modules/", "node_modules"],
    "testPathIgnorePatterns" : ["<rootDir>/node_modules/", "node_modules"]
  }
}

I am not sure exactly what the jest config options should look like. Am I on the right track?

@mulchy - Thanks for taking the time to test it!

Did you checkout the fix-watcher-bug-osx and then run yarn run build, and cd to the packages/jest-cli folder and run yarn link?

Everything you pasted in seems correct.

What version of node are you running? (I tested on 7.7.1 & 7.2.0)
My error coming from at FSEvent.FSWatcher._handle.onchange (fs.js:1282:11) while yours is FSEvent.FSWatcher._handle.onchange (fs.js:1406:11) which might imply a different FSEvent (or imply nothing at all)

@ro-savage yes. Ran it again just to be sure and re-linked it in the failing project, I still see the same errors.

Ξ» jakku jest β†’ Ξ» git fix-watcher-bug-osx β†’ git branch
* fix-watcher-bug-osx
  master
Ξ» jakku jest β†’ Ξ» git fix-watcher-bug-osx β†’ git log --oneline | head -1
ad182a0 Changed jest-haste-map to pass modulePathIgnorePatterns
Ξ» jakku jest β†’ Ξ» git fix-watcher-bug-osx β†’ yarn run build
yarn run v0.19.1
$ node ./scripts/build.js
Building packages
babel-jest.....................................................................[  OK  ]
... edited for brevity

✨  Done in 4.11s.
Ξ» jakku jest β†’ Ξ» git fix-watcher-bug-osx β†’ cd packages/jest-cli
Ξ» jakku jest-cli β†’ Ξ» git fix-watcher-bug-osx β†’ yarn link
yarn link v0.19.1
warning There's already a module called "jest-cli" registered.
✨  Done in 0.17s.
Ξ» jakku jest-cli β†’ Ξ» git fix-watcher-bug-osx β†’

When I originally ran into this bug I was on 7.x, I recently switched back to 6.9.5 for a work thing. Not sure if this is helpful, but here is that line in fs.js https://github.com/nodejs/node/blob/v6.9.5/lib/fs.js#L1406

EDIT: I think I did the link step correctly, when I check my node_modules folder I see this

ls -l node_modules/jest-cli
lrwxr-xr-x 1 ryan.mulcahy staff 35 Mar  3 11:09 node_modules/jest-cli -> ../../../.config/yarn/link/jest-cli

which looks like it is pointing to a local version

Do I need to link jest as well as jest-cli, or something like that?

@mulchy - Oh, it might be when you check out 'fix-watcher-bug-osx' you need to yarn install again, so that you're running sane 1.6.0 (you can also check node_modules, find sane and check the version. Either root directory or within jest-haste-map).

On the default branch jest is running sane 1.5.0

(I tested v6.9.5 and it ran fine on my machine. So it not that)

I'm still not able to run Jest in watch mode:

$ node -v && npm -v && jest --version 
v7.4.0
4.0.5
v19.0.2

macOS v10.12.4

It's throwing the same error again and again:

> jest --watch --no-watchman

2017-04-25 14:24 node[2209] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-04-25 14:24 node[2209] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-04-25 14:24 node[2209] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error watching file for changes: EMFILE
    at exports._errnoException (util.js:1022:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1283:11)

I've increased the max file limit as recommended here with no success.

I also checked @ro-savage PR and even using modulePathIgnorePatternsno luck. Am I missing something here?

I don't think to install watchman is a solution, even if that makes it work, because it's not listed as a dependency and Jest claims it works out of the box in any react project.

Edit: I tried installing watchman-4.7.0 and is still breaks:

> jest --watch

2017-04-25T14:57:32,994: [3163407296] while computing sockname: failed to create /usr/local/var/run/watchman/valverde-state: No such file or directory

Watchman:  watchman --no-pretty get-sockname returned with exit code=1, signal=null, stderr= 2017-04-25T14:57:32,994: [3163407296] while computing sockname: failed to create /usr/local/var/run/watchman/valverde-state: No such file or directory

jest-haste-map: Watchman crawl failed. Retrying once with node crawler.
  Usually this happens when watchman isn't running. Create an empty `.watchmanconfig` file in your project's root folder or initialize a git or hg repository in your project.
  Error: watchman --no-pretty get-sockname returned with exit code=1, signal=null, stderr= 2017-04-25T14:57:32,994: [3163407296] while computing sockname: failed to create /usr/local/var/run/watchman/valverde-state: No such file or directory

2017-04-25T14:57:33,915: [3163407296] while computing sockname: failed to create /usr/local/var/run/watchman/valverde-state: No such file or directory

Watchman:  watchman --no-pretty get-sockname returned with exit code=1, signal=null, stderr= 2017-04-25T14:57:33,915: [3163407296] while computing sockname: failed to create /usr/local/var/run/watchman/valverde-state: No such file or directory

events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: watchman --no-pretty get-sockname returned with exit code=1, signal=null, stderr= 2017-04-25T14:57:33,915: [3163407296] while computing sockname: failed to create /usr/local/var/run/watchman/valverde-state: No such file or directory

    at ChildProcess.<anonymous> (/Users/valverde/dev/dws/frontend/node_modules/sane/node_modules/fb-watchman/index.js:198:18)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:191:7)
    at maybeClose (internal/child_process.js:885:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)

@valgreens - My PR has been merged into master but there hasn't been a Jest release since the merge.

So unless you were running a Jest you built yourself from the repo, the changes the fix won't be there.

@ro-savage ah! that makes more sense, thanks! I'll try to run from the repo reproducing your steps.

Thanks @robzolkos for brew install watchman, would never had found that in a million years!

@ro-savage heads up i just installed the jest 20.0.0 release and have sane 1.6.0 installed but i'm still seeing this emfile error. installed watchman to fix for now, was there any other package upgrade i could be missing? i'm using yarn so everything's pretty locked down obviously

Also having this issue here within a small CRA project. Installing watchmen fixed it for me ...

Any ETA for when the fix will be released? It is still broken for me in jest 20.0.3, node 6.10.3

Any ETA for when the fix will be released?

Any fix that Jest 20 might have is already released as of react-scripts@1.x so if you’re still having issues, I guess Jest 20 didn’t fix them.

We are using an ejected version of Create React App v1.0.5.

node: v6.10.2
npm: 3.10.10
jest: v20.0.3
macOS Sierra: 10.12.4

I get the following error when I run yarn test

2017-05-23 12:11 node[7644] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2017-05-23 12:11 node[7644] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:160
      throw er; // Unhandled 'error' event
      ^

Error: Error watching file for changes: EMFILE
    at exports._errnoException (util.js:1018:11)
    at FSEvent.FSWatcher._handle.onchange (fs.js:1420:11)

But only after I add stylelint-scss to the app
yarn add stylelint-scss --dev

Running this fixes it

brew update
brew install watchman

same as @mistermendez ... haven't yet installes watchman is that now a dependency of create-react-app / jest?

The fix PR #2957 in Jest 20 updated the optionmodulePathIgnorePatterns to correctly ignor the the folders/patterns. Previously it was still load them all and then just skip when it came time to run the test. The PR fixed the issue (for myself anyway. But I am unable to retest as I have left the company that had the issue and don't have access to the source code anymore).

However, create-react-app v1.0.0+ is now using testMatch to decide what it should be watching instead.

Which means the original PR I did might not have any affect, depending how testMatch has been implemented. I don't know if testMatch is fully ignoring the files or if it still loads them then skips when it finds a match (thus causing this issue).

@mistermendez - Since you have ejected. Could you try uninstalling watchman and then updating your jest config to to remove

testMatch: [
      '<rootDir>/src/**/__tests__/**/*.js?(x)',
      '<rootDir>/src/**/?(*.)(spec|test).js?(x)',
    ],

and replace with

modulePathIgnorePatterns: [
      '<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]'
    ],

And then run the tests? And let us know if that fixes the issue?

Hmm. My impression was that testMatch is supposed to be the "new way" of doing things and modulePathIgnorePatterns would eventually get deprecated. Am I wrong? Can we fix testMatch too?

I might be wrong, but from a very quick look at the latest code base.

Jest seems to be watching every file is a project based on its extension, minus the ignored files.

Pinging @pugnascotia @cpojer - should the regex/glob from testMatch be passed to the watcher?

@ro-savage I got it to work with watchman, uninstalled it, added

    "modulePathIgnorePatterns": [
      "<rootDir>[/\\\\](build|docs|node_modules|scripts)[/\\\\]"
    ],

and it works. (w/o watchman)

We might be getting somewhere here. facebook/create-react-app#2395 (comment)

So I'm not a huge fan of adding a dependency like watchman even if it does speed up things with lots of files in your repo. I'll probably install it personally if it does speed things up, but don't want to force it to be a requirement in the README. So it sounds like the main thing you need to do is reduce the amount of files Jest is watching in your repo by adding the modulePathIgnorePatterns and testPathIgnorePatterns configs and including all of the directories you don't need to have Jest watch. That's basically what the root of the problem is correct?

As I just mentioned in the above comment, we’re going to fix this by using fsevents on OS X which doesn’t suffer from this issue. Please track amasad/sane#97.

This is ready for testing; anyone wants to try it?

Yes, would love to get --watch back. What branch should I check out?