jest: Watch mode stopped working on macOS Sierra

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

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 78
  • Comments: 140 (51 by maintainers)

Commits related to this issue

Most upvoted comments

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

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.

For anyone else still having this problem, I was able to resolve it by adding my node_modules directory to watchPathIgnorePatterns in my jest config.

watchPathIgnorePatterns: ["node_modules"]

Credit owed to @reergymerej from here.

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

Feel free to install jest@20.1.0-alpha.3 and beyond, which should not cause any more issues with this.

However, installing watchman via Brew solved the issue for me (with Jest @ 20.0.4).

Ditto.

For anyone else who stumbles on this issue and and doesn’t use Homebrew regularly, the following worked for me after now having this issue over multiple projects for several months:

  1. Take ownership of your local directory (not required with new versions of homebrew):

    $ sudo chown -R $USER /usr/local/
    
  2. Update homebrew:

    $ brew update
    
  3. Install watchman:

    $ brew install watchman
    

Enjoy properly working Jest with --watch 😃

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

Per https://github.com/facebookincubator/create-react-app/issues/713#issuecomment-249197672, uninstalling Watchman fixes the issue so it’s either a problem with Watchman, or its Jest integration on Sierra.

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

Upgrading to jest@20.1.0-alpha.3 sees this message hang on the screen forever: Determining test suites to run...

However, installing watchman via Brew solved the issue for me (with Jest @ 20.0.4).

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

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

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

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

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

I also summarized a few workarounds here.

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.

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.

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

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 😃

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.

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.

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

None of the above solutions worked while I was working inside a tmux session. Steps to fix:

  • Exit tmux session
  • brew uninstall watchman
  • brew install watchman
  • yarn test
  • Enter tmux session
  • yarn test

node: 8.3.0 npm: 5.3.0 jest: 20.0.4 macOS Sierra: 10.12.6

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

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.

Reportedly, this may fix the issue:

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

I had exactly the same problem. $ brew install watchman worked perfectly for me aswell

Incredibly strange, I was trying to figure this out, I uninstalled watchman using brew uninstall watchman like @BookOfGreg and it now works.

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.

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.

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

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

I was not using create-react-app, and i’ve solved removing the --watch option and using instead --no-watchman

How i fixes this was.

At first i tried brew install watchman and yes it worked like charm, However i was thinking if this could be the real issue? i again uninstalled it brew uninstall watchman

then i removed my node modules rm -rf node_modules and hit npm i again also when i hit npm list --depth=0 I had Err of UNMET PEER DEPENDENCY jest@20.0.4 and then i moved jest from dependencies to devDependencies using npm i -D jest

in short

  1. rm -rf node_modules
  2. npm i
  3. npm i -D jest (if required)

might help someone. 😃

After adding Enzyme 3.3.0, this issue started for my team using an ejected version of CRA. We’re all on High Sierra if that matters. I explored all of the options outlined in the many links here and, aside from brew install watchman, nothing seemed to work. That was not an acceptable solution for me so I continued to investigate. Ultimately, updating to Jest 23.1.0 resolved the issue.

@dchambers I had the opposite issue: I did a brew uninstall watchman and Jest started running! See facebook/watchman/issues/20

Also didn’t have Watchman installed & brew install watchman fixed. Bizarrely, everything was working until I installed Enzyme into my project, after which the problem appeared in twice before the test run aborted. Rolling the project back did not fix. I’ve had to document this work around, but I’m not understanding why it happened, or how to avoid it in the future (given homebrew isn’t always an option).

Node: v6.9.5

I didn’t have Watchman installed, but a brew install watchman fixed this for me.

I get this error with jest 21, but not with jest 20.

I just wanted to pop in and add that brew install watchmen only worked for me after following the create-react-app README verbatim:

watchman shutdown-server
brew update
brew reinstall watchman

@kirkstrobeck probably the easiest way is to clone the repo replacing your local copy of sane (which will be in node_modules/jest/node_modules/sane or node_modules/sane).

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

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

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.

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

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.

Confirming the same issue. Installing watchman fixed the problem.

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.

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

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.

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.

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

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?

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.

@cpojer Should we document Watchman in CRA User Guide?

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

A few other possibly related threads:

https://github.com/ember-cli/ember-cli/issues/6259 https://github.com/facebook/watchman/issues/358

Can you try any suggestions there and report back?