nx-console
nx-console copied to clipboard
ENOSPC: System limit for number of file watchers reached
ENOSPC: System limit for number of file watchers reached caused by NX opening far too many INOTIFY watchers.
NX has over 20,000 registered watchers. Suspect node_modules folder is being watched.
Current Behavior
When the NRWL extension is activated in my NX project (containing several Angular and NodeJS Express projects) I'm seeing that there are several thousand inotify watchers. This regularly causes my Angular Serve commands to fail because it is unable to register enough watchers for it's own purposes.
For example: nrwl.angular-console-18.18.0/nxls/main.js uses 21842 Inotify Watchers whereas nx serve uses less than 1000.
I suspect that NX is watching the node_modules directory. I have added "node_modules/" to an .nxignore file in the root of my project but this doesn't seem to have an impact.
Disabling the NX Extension in VSCode fixes the issue (because none of the watchers are being registered).
Expected Behavior
I do not expect NX VS Code extension to be registering so many INotify watchers causing my other activies to fail.
Steps to Reproduce
- Create a VS Code Dev Container (Image: mcr.microsoft.com/devcontainers/typescript-node:1-20-bullseye)
- Add a post create command of "yarn global add nx && yarn"
- Install the NX Extension within the Dev Container (add it to the
- Create a project with 3 Angular apps, and 2 back end NodeJS Express apps
- Reload the VS Code window
- Run the script here which counts the number of active INOTIFY watchers.
- Observe that NX is using a large amount of INOTIFY watchers
Failure Logs / Images / Videos
When the error occurs, nx serve (or nx build --watch) on the angular projects give many thousand error lines saying:
ENOSPC: System limit for number of file watchers reached
Environment
Node : 20.11.1 OS : linux-x64 yarn : 1.22.19
nx (global) : 18.1.3 nx : 18.1.2 @nx/js : 18.1.2 @nx/jest : 18.1.2 @nx/linter : 18.1.2 @nx/eslint : 18.1.2 @nx/workspace : 18.1.2 @nx/angular : 18.1.3 @nx/cypress : 18.1.2 @nx/devkit : 18.1.2 @nx/esbuild : 18.1.2 @nx/eslint-plugin : 18.1.2 @nx/express : 18.1.2 @nx/node : 18.1.2 @nx/storybook : 18.1.2 @nrwl/tao : 18.1.2 @nx/web : 18.1.2 @nx/webpack : 18.1.2 typescript : 5.3.3
Community plugins: @storybook/angular : 7.6.10
The following packages should match the installed version of nx
- @nx/[email protected]
- @nrwl/[email protected]
To fix this, run nx migrate [email protected]
- Nx Console version: v18.18.0
- VSCode version: v1.87.2 - Ubuntu 22.04 LTS
Note: Follow up, I ran the migrate to 18.1.3 of nx/angular and still getting the same issue
Hey thanks for the report :) Is there something in your .yarn/cache folder? If yes, try adding that to .nxignore too. I'm reworking the watching process right now so this should be fixed in the next release.
No, there is no .yarn/cache folder. I see a .yarn/releases folder with 1 file in there: yarn-1.22.19.cjs @ 5.1mb.
Thank you for looking into this!
:) Does it say which files are being watched? Is it really node_modules?
Is it really node_modules?
I am fairly confident.
I opened the file /proc/1641254/fdinfo/31 where 161254 is the PID for the node nx-console process launched inside the dev container. This file has over 20,000 inotify handles listed.
I picked some lines at random from that file to see an output like this:
inotify wd:1386 ino:620714 sdev:10300002 mask:3ce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:140762004f31d27d
inotify wd:1385 ino:620716 sdev:10300002 mask:3ce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:160762009c51bf25
inotify wd:1384 ino:620713 sdev:10300002 mask:3ce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:1307620001620b39
inotify wd:1383 ino:621c31 sdev:10300002 mask:3ce ignored_mask:0 fhandle-bytes:8 fhandle-type:1 f_handle:311c62001e6e829c
Then, using a simple script, I traced back the inode for those files, and each of them was a file inside node_modules:
- 621c2f = /node_modules/@babel/preset-env/node_modules/@babel/plugin-transform-reserved-words/node_modules/@babel/core/lib/config/validation
- 620714 = /node_modules/@babel/preset-env/node_modules/@babel/plugin-transform-reserved-words/node_modules/@babel/core/lib/config
- 601130 = /node_modules/zone.js
Hope this helps.
Hey I just released some changes to file watching in Nx Console. Can you check and see whether this issue persists on the latest version?
I have the same problem with the latest version of NX Console
@ahmedyouseeff can you paste your nx report as well as VSCode logs?
I tried to upgrade to version 19.0.0 and did not consume much watcher for my angular + nodejs projects. For my case after run "nx report" I got the recommend to fix the dependency on difference version
"The following packages should match the installed version of nx
- @nrwl/[email protected]"
I'm remove the old dependency by "rm -rf node_module/@nrwl/devkit" Then npm install everything back to normal not rerquire to add more watcher.
@ahmedyouseeff @jamesikanos can you reproduce this issue on the latest version of Nx Console (and if you can, Nx) anymore?
Hey :) After our watching changes, this should be resolved so I'll close this issue for now. Please do let me know if you still run into it and I will investigate further! Thanks a lot
Hi, I got the same issue when I upgrade from [email protected] to [email protected]. In a monorepo with multiple nextjs application, when runnning "nx dev" the file watchers limit were reached. As soon as I downgraded to 19.1.1 it was working as expected (no watchers were added).
is this happening only with Nx Console installed? Or also with just nx? If yes, could you create an issue in the nx repo?