jest: Bug: Watch mode on Linux causes a ENOSPC Node.js error
Versions:
- Yarn: v0.21.3
- Node: v6.9.2
- npm: 3.10.9
- Ubuntu: 16.10
Installed using: yarn global add jest
(With a chown
at ~/.config/yarn/global/node_modules/
)
Command failed: jest -c lib/tools/testing/jest.config.json --no-cache --watch
If I run
jest -c lib/tools/testing/jest.config.json --no-cache
testing works 100% fine.
Error message:
fs.js:1431
throw error;
^
Error: watch /home/fooBar/dev/blah/lib/tools/testing/node_modules/core-js/modules ENOSPC
at exports._errnoException (util.js:1022:11)
at FSWatcher.start (fs.js:1429:19)
at Object.fs.watch (fs.js:1456:11)
at NodeWatcher.watchdir (/home/fooBar/.config/yarn/global/node_modules/sane/src/node_watcher.js:148:20)
at Walker.<anonymous> (/home/fooBar/.config/yarn/global/node_modules/sane/src/node_watcher.js:361:12)
at emitTwo (events.js:106:13)
at Walker.emit (events.js:191:7)
at /home/fooBar/.config/yarn/global/node_modules/walker/lib/walker.js:69:16
at go$readdir$cb (/home/fooBar/.config/yarn/global/node_modules/graceful-fs/graceful-fs.js:149:14)
at FSReqWrap.oncomplete (fs.js:123:15)
Tmp dir: yarn config set tmp /tmp/
Disk free space: df -h /
(11% used)
Jest config: at lib/tools/testing/jest.config.json
{
"clearMocks": true,
"bail": true,
"transform": {
".(ts|tsx)": "<rootDir>/lib/tools/testing/node_modules/ts-jest/preprocessor.js"
},
"testResultsProcessor": "<rootDir>/lib/tools/testing/node_modules/ts-jest/coverageprocessor.js",
"testMatch": [
"**/__tests__/*.(ts|tsx|js)"
],
"moduleFileExtensions": [
"ts",
"tsx",
"js"
],
"moduleDirectories": [
"node_modules",
"<rootDir>/lib/tools/testing/node_modules"
],
"collectCoverage": true,
"coverageDirectory": "./reports/",
"coverageReporters": [
"clover",
"lcov",
"text-summary"
],
"coverageThreshold": {
"global": {
"branches": 50,
"functions": 80,
"lines": 60
}
},
"collectCoverageFrom": [
"{src,lib}/**/*.{ts,js}",
"!lib/{tools}/**/*",
"!**/{node_modules,vendor}/**"
]
}
About this issue
- Original URL
- State: closed
- Created 7 years ago
- Reactions: 18
- Comments: 78 (6 by maintainers)
Commits related to this issue
- tests: ignore node_modules from jest watcher Avoids ENOSPC error on docker/linux https://github.com/facebook/jest/issues/3254#issuecomment-457027880 Signed-off-by: Peter Lyons <pete@reactioncommerce... — committed to reactioncommerce/reaction by focusaurus 5 years ago
- 🐛 Ignore node_modules in server jest config I was getting an error when VSCode started: 'Starting Jest in Watch mode failed too many times and has been stopped'. This issue (https://github.com/faceb... — committed to rhinodavid/upswyng by deleted user 5 years ago
- 🐛 Ignore node_modules in server jest config (#171) I was getting an error when VSCode started: 'Starting Jest in Watch mode failed too many times and has been stopped'. This issue (https://github.co... — committed to CodeForBoulder/upswyng by rhinodavid 5 years ago
- Update package.json https://github.com/facebook/jest/issues/3254#issuecomment-488434727 — committed to DevExpress/DevExtreme by AlekseyMartynov 4 years ago
- Merge renovation (#13214) * preact button * add generator * Template * add generation to build task * get generator from npm * update generator * Add the elementAttr property * A... — committed to DevExpress/DevExtreme by churkin 4 years ago
From my findings its not related to Jest at all. On Linux (or Mac) we have a max number of system watchers we can place at an IO level (from my understanding). So for large projects, it seems that Jest is trying to watch just way to many files.
To fix:
Source: Node.JS Error: ENOSPC
This means there is no space on your drive. Please cleanup your disk.
Just recently switched from Windows 7 to Ubuntu 16.04.2 LTS and Jest was working great in Windows but failed to run under Linux for the same reasons listed above. It only seems to fail if you add the
--watch
flag.Firstly I took @cpojer advice and installed watchmen as per docs and ran the
jest --watch
again and I got the following errors:This was useful as it tells you what to do, so I then used the fix from @maraisr and jest is now working on Ubuntu 🎉 🍻
Thank you for figuring this out @maraisr @cpojer 👍 Do you think something should be added to the Jest website?
Unfortunately we do not have resources to debug this on Linux. If you have time and you could take a look and help us with a pull request to fix it, that would be greatly appreciated.
@cpojer not sure if you read the issue, but;
was mentioned in there - disk space although reported as the issue, is actually not the issue.
I am having the same issue, and there’s definitely free disk space
I fixed it excluding
node_modules
with themodulePathIgnorePatterns
setting.Add this to your package.json:
Getting this on ubuntu 18.10 when i run “npm start” on my untouched virgin create-react-app WORKED!!! SOLUTION echo fs.inotify.max_user_watches=2048000 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
This should be the top answer. People - please bump this. Why would you simply say “oh, out of memory/resources - give it more memory/resources” without examining the cause?
@maraisr Great,
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
worked for me on Ubuntu 18.04.1 LTSI don’t see why this bug is “Closed.” Forcing the user to
sudo
for a mundane task is certainly a bug.It’s a bug unique to Jest: mocha, guard, etc. all watch specific subdirectories, not
.
, to avoid this problem. (The list of subdirectories could be optional.)@cpojer I’ll take a look - but I also believe it is not limited to the Linux OS. Regardless, do you mind re-opening this issue?
after that, just remove
node_modules
folder and runnpm install
again.Thanks for investigating, if you install watchman, it should work.
I was getting this issue, when I had two VSCode instances opened.
In jest 21 i never had this problem. vscode is competing with jest for watching the files. when i close vscode, jest starts to work correctly.
this is the real answer
IMO, it’s unacceptable that there should be a watch on
node_modules
To get away from this bug just use sublime/atom/gedit. Or you can close VSCode while building/debugging.
Future visitors and @sunnykeshri @JimmyBastos @BrotherDonkey @CodeMonkeyG, for my sanity please stop propagating the watch limit fix.
Perfectly solved my problem, thank you very much!
@vspedr not sure - I can take a look!
But we are touching system files there, so for security you kinda need elevated permissions. If you can make yourself a sudoer i believe you can run those commands without sudo.
But yeah - i’ll take a look and see what I can come up with.
For future visitors, @pomber’s solution is objectively vastly better than increasing the watch limit:
I got this error when I update the project dependencies. To solve I just removed the and install the
node_modules
This took me SO long to find and finally fix. I started doing workarounds again and again. Thank you @samit4me !
Since the last few comments have been suggesting the earlier workaround, and the later fix is starting to get buried, I feel it is necessary to reiterate for future readers (and @pradeepsrawat029 @karsa87 @igorgoiis ) that you should first try the later fix if applicable, which was originally not possible because of a jest bug:
Thanks resovel o problema já tava procurando a horas o que era esse rro
Funny thing about
fs.inotify.max_user_watches=524288
In my case it seems the project is large enough that524288
isn’t big enough of a number. So… wellfs.inotify.max_user_watches=2048000
helped. Might also be related to the matter of opening a lot of stuff in vs code on the side.echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
fixed it for me as well 👍Please reopen or add the fix to the troubleshooting for testing.
@maraisr
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
this solution does not work on my mac os 10.13.4 it returns the error below
sysctl: illegal option -- p usage: sysctl [-bdehiNnoqx] name[=value] ... sysctl [-bdehNnoqx] -a sysctl: illegal option -- p usage: sysctl [-bdehiNnoqx] name[=value] ... sysctl [-bdehNnoqx] -a
Thanks Bro @maraisr
Thanks @maraisr
thank yout for you answer it’s work for me
Thank you for your best answer.
This command will increase the number of allowed watchers:
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Sourcemight be there is some permission issues try Sudo npm start
Just a note for the record: the present proper fix didn’t work until #7585 that fixed #7544 .
Oh Hey @scotthovestadt! Hope you’re well!
Your solution worked for me, @maraisr!
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p
Thanks!This was my error for anyone who’s interested: Logs for your project will appear below. Press Ctrl+C to exit. (node:19425) UnhandledPromiseRejectionWarning: Error: ENOSPC: System limit for number of file watchers reached, watch ‘/home/claire/Documents/my-app-name’ at FSWatcher.start (internal/fs/watchers.js:165:26) at Object.watch (fs.js:1274:11) at NodeWatcher.watchdir (/home/claire/Documents/my-app-name/node_modules/sane/src/node_watcher.js:175:20) at new NodeWatcher (/home/claire/Documents/my-app-name/node_modules/sane/src/node_watcher.js:45:8) at createWatcher (/home/claire/Documents/my-app-name/node_modules/jest-haste-map/build/index.js:780:23) at Array.map (<anonymous>) at HasteMap._watch (/home/claire/Documents/my-app-name/node_modules/jest-haste-map/build/index.js:936:44) at _buildPromise._buildFileMap.then.then.hasteMap (/home/claire/Documents/my-app-name/node_modules/jest-haste-map/build/index.js:355:23) at processTicksAndRejections (internal/process/next_tick.js:81:5) (node:19425) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1) (node:19425) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code. ENOSPC: System limit for number of file watchers reached, watch ‘/home/claire/Documents/my-app-name’ ENOSPC: System limit for number of file watchers reached, watch ‘/home/claire/Documents/my-app-name’
I run with sudo … and it works to me
Be aware that
/etc/sysctl.conf
is typically overwritten when upgrading (eg from Ubuntu 16 to 18 LTS) and will remove the higher limit. I was warned about this, but it’s easy to miss in a sea of other similar warnings. Even though I saw themax_user_watches
diff, I was still thrown for a loop this morning when I first hit the error, as it is not obvious that these things are connected. However, once I landed on this issue page it was clear what I needed to fix.Hooray for re-solving an issue I had fixed two years ago 😆
Cheers for the point in the right direction on this. I had the same issue with watch failing, but in this case only one instance of VSCode running. Closing that, then running my project and reopning, resolved it.