OS X: "Error: EMFILE: too many open files, watch" when running tests
mdr opened this issue · comments
Is this a bug report?
Maybe. This may well not be a create-react-app
issue as such, but hoping someone could point me in the right direction.
Environment
Environment:
OS: macOS High Sierra 10.13.3
Node: 10.1.0
Yarn: 1.6.0
npm: 5.6.0
Watchman: Not Found
Xcode: Not Found
Android Studio: Not Found
Packages: (wanted => installed)
react: ^16.4.0 => 16.4.0
react-dom: ^16.4.0 => 16.4.0
react-scripts: 1.1.4 => 1.1.4
Steps to Reproduce
npx create-react-app new-app
- Add the following dependencies to
package.json
:
"dependencies": {
"@material-ui/core": "^1.0.0",
"@material-ui/icons": "^1.0.0",
"classnames": "^2.2.5",
"react": "^16.4.0",
"react-dom": "^16.4.0",
"react-router-dom": "^4.2.2",
"react-scripts": "1.1.4",
"recompose": "^0.27.1",
"typeface-roboto": "^0.0.54"
},
"devDependencies": {
"@storybook/addon-actions": "^3.4.5",
"@storybook/addon-knobs": "^3.4.5",
"@storybook/addon-links": "^3.4.5",
"@storybook/addon-notes": "^3.4.5",
"@storybook/addons": "^3.4.5",
"@storybook/react": "^3.4.5",
"babel-core": "^6.26.3",
"babel-runtime": "^6.26.0",
"cypress": "^2.1.0",
"react-test-renderer": "^16.4.0"
},
- Run
yarn test
Expected Behavior
Tests are executed.
Actual Behavior
$ yarn test
yarn run v1.6.0
(node:1262) [DEP0005] DeprecationWarning: Buffer() is deprecated due to security and usability issues. Please use the Buffer.alloc(), Buffer.allocUnsafe(), or Buffer.from() methods instead.
$ react-scripts test --env=jsdom
2018-05-30 13:31 node[1264] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2018-05-30 13:31 node[1264] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
2018-05-30 13:31 node[1264] (FSEvents.framework) FSEventStreamStart: register_with_server: ERROR: f2d_register_rpc() => (null) (-22)
events.js:167
throw er; // Unhandled 'error' event
^
Error: EMFILE: too many open files, watch
at FSEvent.FSWatcher._handle.onchange (fs.js:1352:28)
Emitted 'error' event at:
at FSEvent.FSWatcher._handle.onchange (fs.js:1358:12)
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
Other
I've tried first raising the limit of open files to 65536, but still get the above error:
$ ulimit -a
...
open files (-n) 65536
...
Any ideas on how to work around this? Thanks!
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)"
Thanks, that fixes the problem -- what's the story on this one, out of interest?
Machines vary, but there is a limit to the number of open files (because of how it watches, more on that later) -- if you use sudo
it might fix it, but that's a meh fix.
Lots of people don't hit this until they start depending on a ton of dependencies, which is why there's not many issues about it.
Watchman is specially designed to watch arbitrarily large number of files without issue, and people normally install it by the time their applications grow to such a large size because Jest recommends it in the docs somewhere iirc.
Anyway, the important part of the backstory is that newer versions of Jest watch files differently now to prevent this issue, and that version is available in the 2.0 beta.
1.0 is using an older version of Jest which a patch-release isn't going to be cut for.