nrwl / nx

Smart Monorepos ยท Fast CI

Home Page:https://nx.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error Popup on every nx command (probably from node_modules\nx\src\daemon\server\start.js)

Jejuni opened this issue ยท comments

Current Behavior

When running any nx command, like nx run my-app:build or nx run my-app:test for the first time (after a reboot, for instance) a cmd window pops up, simply stating [process exited with code 1 (0x00000001)]:

image

The run still seemingly completes correctly.
After that every subsequent run of any nx command completes without error.

On closer inspection I found that a node process is spawned and called with the following arguments:

"C:\Program Files\nodejs\node.exe" C:\my-workspace\node_modules\nx\src\daemon\server\start.js

This process persists even after closing the terminal.
Killing this process manually and then running any nx command makes the error come back.

Expected Behavior

No cmd windows with errors pop up.

Steps to Reproduce

This was encountered on a Windows machine version 21H2 (OS Build 22000.739).
Used shell was PowerShell Core 7.2.4 AND regular PowerShell 5.1.22000.653

Repro:

  • run npx create-nx-workspace@latest test-workspace, choose angular and scss and cloud integration.
  • run nx run my-app:test
  • Error should appear

Environment

nx report of created workspace:

Node : 16.15.0
OS   : win32 x64
npm  : 8.5.5

nx : 14.3.6
@nrwl/angular : 14.3.6
@nrwl/cypress : 14.3.6
@nrwl/detox : Not Found
@nrwl/devkit : 14.3.6
@nrwl/eslint-plugin-nx : 14.3.6
@nrwl/express : Not Found
@nrwl/jest : 14.3.6
@nrwl/js : 14.3.6
@nrwl/linter : 14.3.6
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : Not Found
@nrwl/nx-cloud : 14.1.2
@nrwl/nx-plugin : Not Found
@nrwl/react : Not Found
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : 14.3.6
@nrwl/web : 14.3.6
@nrwl/workspace : 14.3.6
typescript : 4.7.4
---------------------------------------
Community plugins:

This also happens to me. The curious thing is that with the NX Console Plugin installed it spawns a window for the error, but if the extension is disabled it only shows an error inside VSCode. It also stops showing after some time, after VSCode is closed and opened again.

PowerShell Core 7.2.5
Windows 11 22H2
VSCode 1.68.1
Node: 18.4.0
npm 8.12.2
"@nrwl/angular": "^14.3.6",
"@nrwl/cli": "14.3.6",
"@nrwl/cypress": "14.3.6",
"@nrwl/eslint-plugin-nx": "14.3.6",
"@nrwl/express": "^14.3.6",
"@nrwl/jest": "14.3.6",
"@nrwl/linter": "14.3.6",
"@nrwl/node": "14.3.6",
"@nrwl/workspace": "14.3.6",

This happens to me too. Since that one node process is never killed after build script, it blocks the dist folder from being rewritten on next build script. Apparently NX thinks the project has no changes made, so it skips building and uses the one from cache - thus leaving you with an outdated build. To fix that you have to manually kill the remaining node process.

NX report:

Node : 16.12.0
OS   : win32 x64
yarn : 1.22.17

nx : 14.3.3
@nrwl/angular : Not Found
@nrwl/cypress : 14.3.3
@nrwl/detox : Not Found
@nrwl/devkit : 14.3.3
@nrwl/eslint-plugin-nx : 14.3.3
@nrwl/express : Not Found
@nrwl/jest : 14.3.3
@nrwl/js : 14.3.3
@nrwl/linter : 14.3.3
@nrwl/nest : Not Found
@nrwl/next : Not Found
@nrwl/node : 14.3.3
@nrwl/nx-cloud : Not Found
@nrwl/nx-plugin : Not Found
@nrwl/react : 14.3.3
@nrwl/react-native : Not Found
@nrwl/schematics : Not Found
@nrwl/storybook : 14.3.3
@nrwl/web : 14.3.3
@nrwl/workspace : 14.3.3
typescript : 4.7.3

We have tried to reproduce this but have not been able to. ๐Ÿ˜ž

In #11247, the user was using the newer Windows Terminal but here I see people are using Powershell + Powershell Core ๐Ÿค”

If anybody else has information that might help us reproduce this, please share! We will continue to try to reproduce it with any additional information provided.

We have tried to reproduce this but have not been able to. ๐Ÿ˜ž

In #11247, the user was using the newer Windows Terminal but here I see people are using Powershell + Powershell Core ๐Ÿค”

If anybody else has information that might help us reproduce this, please share! We will continue to try to reproduce it with any additional information provided.

I also posted above. I am on Windows 11, with Windows Terminal, PowerShell 7.2.5.
I solved the issue with the popup by disabling the "daemon" in nx.json:

nx.json
...
 "tasksRunnerOptions": {
    "default": {
      "runner": "nx/tasks-runners/default",
      "options": {
        "cacheableOperations": ["build", "lint", "test", "e2e"],
        "useDaemonProcess": false
      }
    }
  }, 
...

I hope this can shine some light on the problem, but I think this is more of a workaround than a full solution.

Edit:
I just tried creating a new nx workspace, with a base angular app.
When I open the project in VSCode, the terminal window opens up immediately with the error.

Install finishes at around 2:30

deamon.mp4

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! ๐Ÿ™

Not a stale.

@FrozenPandaz
Windows just gave me this popup, I don't think it is related, just wanted to document it.
image

You can check my exact setup here in the video

We have tried to reproduce this but have not been able to. ๐Ÿ˜ž
In #11247, the user was using the newer Windows Terminal but here I see people are using Powershell + Powershell Core ๐Ÿค”
If anybody else has information that might help us reproduce this, please share! We will continue to try to reproduce it with any additional information provided.

I also posted above. I am on Windows 11, with Windows Terminal, PowerShell 7.2.5. I solved the issue with the popup by disabling the "daemon" in nx.json:

nx.json
...
 "tasksRunnerOptions": {
    "default": {
      "runner": "nx/tasks-runners/default",
      "options": {
        "cacheableOperations": ["build", "lint", "test", "e2e"],
        "useDaemonProcess": false
      }
    }
  }, 
...

I hope this can shine some light on the problem, but I think this is more of a workaround than a full solution.

Edit: I just tried creating a new nx workspace, with a base angular app. When I open the project in VSCode, the terminal window opens up immediately with the error.

Install finishes at around 2:30
deamon.mp4

Also now having the same problems as #11247
After using nx generator to add libs / components. 8-10 console windows open and then immediately close again.
That was probably there from the beginning, but I haven't used the generators in a while.

Also recently upgraded to node 16.17.0, but problem still persists.

I've spent some more time analyzing the problem.

When navigating to an Nx Project and running nx daemon --start the same problem as described initially appears. That is, a console window spawns that simply states [process exited with code 1 (0x00000001)].
Running nx daemon after that, however, prints Nx Daemon is currently running: and then a link to the logs and a ProcessId.

Using nx daemon --start --background=false to run the daemon in the current process does NOT produce any errors or popups.

I've also tried debugging the daemon.js, but since the error only happens when the code that causes the error runs in the background I've not gotten very far.

@FrozenPandaz does any of this help with troubleshooting the issue on your side?

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! ๐Ÿ™

Not stale.

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! ๐Ÿ™

Not stale, and has gotten much worse with the last update.

As far as I can see, the --background=false flag does not exists/work anymore. I couldn't find any reference to it in the docs or nx daemon help anymore and using the flag still tries to run the daemon in a background process.

All my colleagues are having the same problem on their windows machines.
There's no way to work with the nx daemon in its current state and the only course of action is to just disable it.

Please take another look at the problem.

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! ๐Ÿ™

I can only agree with @Jejuni. It has become worse on Windows. It would be great if you can fix that. Please do not stale.

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! ๐Ÿ™

Not stale.
@FrozenPandaz any new developments regarding this?

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! ๐Ÿ™

Not stale.

I'd like to share a video of what this looks like for me, running Lerna v6.0.3 on Windows 11. Using git bash in Windows Terminal, but also does the same when run via powershell directly.

nx-lerna-opening-tabs.mp4

The worst part is that when the new terminals open, they take focus from whatever app you are working on, making it impossible to use my computer when running tasks in Lerna/Nx.

I'd like to share a video of what this looks like for me, running Lerna v6.0.3 on Windows 11. Using git bash in Windows Terminal, but also does the same when run via powershell directly.
nx-lerna-opening-tabs.mp4

The worst part is that when the new terminals open, they take focus from whatever app you are working on, making it impossible to use my computer when running tasks in Lerna/Nx.

Not a fix per see, but you might mitigate this by changing this settings in the terminal, to make it so that the tab doesn't persist.
image

@krokofant Thanks - I already had it set like that earlier, but the opening tabs still steal focus even though they immediately close, so unfortunately it is still just as unusable :(

This issue has been automatically marked as stale because it hasn't had any recent activity. It will be closed in 14 days if no further activity occurs.
If we missed this issue please reply to keep it active.
Thanks for being a part of the Nx community! ๐Ÿ™

Still an issue.

I also have the Command Prompt Pinata ๐Ÿช…, but I even have it when saving a file that's monitored by Nx.. It's driving me crazy ๐Ÿคฏ

I have the same problem when working in VSCode on Windows 11. It always opens up terminal windows that close again immediately but as they steal focus it is basically not possible to work with it.

This issue is really embarrassing when trying to promote nx in a demo or so. Kills my machine with popups. Iโ€™m now afraid to demo anything nx on windows. ๐Ÿ˜ฟ

Out of curiosity

  1. what node package manager is everyone using?
  2. Are u using workspaces?

Yarn:yes

@jbadeau Yes, yarn v1.22.19, with workspaces (via Lerna)

I have it with npm and yarn. Not using workspaces. It also seems not related to vscode, the popups also pop up when using nx commands in the terminal.

commented

Npm v8.19.2 with workspaces, problem happens in vs-code, WebStorm, and just regular terminal

i think its one process per lib in this daemon or so...

nx.mp4
commented

It happens to me as well and it's driving me insane

We are also experiencing this, and we use latest:

  • NX: 15.6.3
  • NX console: 17.29.0
  • node: 18.14.0 (The issue was also on node: 16.16.0)
  • yarn: 1.22.19
  • VS Code on Windows: 1.75.0
commented

@meeroslav @Coly010 can this get looked into? A lot of people are experiencing this.

Sorry for this persistent annoying problem. You can switch off daemon by setting the env variable NX_DAEMON=false which will stop the daemon from being started. Unfortunately, you will also lose all the benefits. The daemon runs in the background and recalculates the project graph on every change so that when you run the nx command in the terminal or within your IDE (e.g. eslint) the graph is already up to date and there is no cold start or graph mismatch (in case of IDE).

But based on your reports, it seems that the daemon is crashing anyway so you wouldn't lose much.

Perhaps @JamesHenry can provide more information as he was the original author of that functionality.

I havenโ€™t been involved in the daemon for a long time Iโ€™m afraid so canโ€™t comment further. Rest assured folks this is a top priority for the team to resolve, please follow Miroโ€™s advice about disabling the daemon in the meantime

I assume that this is caused by the child_process calls to spawn with the detached option. The windowsHide option does not seem to do anything when detached option is used on Windows. (packages\nx\src\daemon\client\client.ts)

Just FYI, this also happens with the NX Console VSCode plugin.
So even if you have the deamon turned off, if you have the plugin enabled it spawns a console, for example when you start VSCode and the plugins are initializing.

Here is a short video of enabling the plugin:

nx.console.mp4
 >  NX   Report

   Node : 18.13.0
   OS   : win32 x64
   npm  : 9.3.1
   
   nx : 15.6.3
   @nrwl/angular : Not Found
   @nrwl/cypress : 15.6.3
   @nrwl/detox : Not Found
   @nrwl/devkit : 15.6.3
   @nrwl/esbuild : Not Found
   @nrwl/eslint-plugin-nx : 15.6.3
   @nrwl/expo : Not Found
   @nrwl/express : 15.6.3
   @nrwl/jest : 15.6.3
   @nrwl/js : 15.6.3
   @nrwl/linter : 15.6.3
   @nrwl/nest : Not Found
   @nrwl/next : Not Found
   @nrwl/node : 15.6.3
   @nrwl/nx-cloud : Not Found
   @nrwl/nx-plugin : Not Found
   @nrwl/react : 15.6.3
   @nrwl/react-native : Not Found
   @nrwl/rollup : 15.6.3
   @nrwl/schematics : Not Found
   @nrwl/storybook : Not Found
   @nrwl/web : 15.6.3
   @nrwl/webpack : 15.6.3
   @nrwl/workspace : 15.6.3
   @nrwl/vite : Not Found
   typescript : 4.9.5
   ---------------------------------------
   Local workspace plugins:
   ---------------------------------------
   Community plugins:

Hey all, I found the root cause of this. And it comes in two parts:

  1. We use a implementation that calls git to do some file hashing within the daemon (even outside the daemon, but only once or twice). And here, we missed a detached: true in that spawn call.
  2. We also use the @parcel/watcher package, and appears to do some spawning in the background whenever files change. (This is why some folks are seeing dozens of pop ups because dozens of changes are happening). I'm going to investigate this one a little bit more to see if we can do some configuration on our side before I make an issue on their board.

We're really sorry that it's taken this long to come to a root cause, and thank you everyone for your patience and understanding.

The light is visible at the end of this tunnel ๐Ÿ™‚

Oh, I want to clarify that there was no issue with the @parcel/watcher package. I found the issue that I was coming across that was only in the Nx repo. I'll have a PR up to fix this soon.

@Cammisuli sadly this problem is back in the newest version, also if the NX Console extension is disabled popups happen less frequently :\

Node : 18.15.0
   OS   : win32 x64
   npm  : 9.6.1

   nx                      : 15.8.6
   @nrwl/js                : 15.8.6
   @nrwl/jest              : 15.8.6
   @nrwl/linter            : 15.8.6
   @nrwl/workspace         : 15.8.6
   @nrwl/cli               : 15.8.6
   @nrwl/cypress           : 15.8.6
   @nrwl/devkit            : 15.8.6
   @nrwl/eslint-plugin-nx  : 15.8.6
   @nrwl/express           : 15.8.6
   @nrwl/node              : 15.8.6
   @nrwl/react             : 15.8.6
   @nrwl/rollup            : 15.8.6
   @nrwl/tao               : 15.8.6
   @nrwl/web               : 15.8.6
   @nrwl/webpack           : 15.8.6
   typescript              : 4.9.5

NX Console version: 17.32.0

Funnily enough, it works perfectly in 15.8.5.

It can be easily reproduced by creating a new NX Node Standalone app, and running 'npm run start':
image

The problem doesn't exist if the app is created with the 15.8.5 version.

Also, I keep getting 'Watch error: Daemon closed the connection' when running 'npm run start', but not sure if that is related to the same problem.

This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.