nx icon indicating copy to clipboard operation
nx copied to clipboard

"nx serve" on Windows with node app (framework: none) crashes any time any time a source file is saved: "Command failed: taskkill /pid xxx /T /F | The process "xxx" not found."

Open hi2u opened this issue 1 year ago โ€ข 5 comments

Current Behavior

  • I'm on a Windows machine
  • I have a new empty node app (or any node app with more code)
    • When generating the node app, I pick framework = none
  • While running nx serve <appname> ...
  • If I save any of my source code .ts files (even without any changes to content), nx serve crashes with an error from taskkill.exe:
C:\my-monorepo-dir>nx serve nodeapp4 --verbose

> nx run nodeapp4:serve:development

Hello World

>  NX  Process exited with code 0, waiting for changes to restart...

...... ๐Ÿ’พ I save main.ts at this point ......

>  NX  File change detected. Restarting...

node:child_process:399
      ex = new Error('Command failed: ' + cmd + '\n' + stderr);
           ^

Error: Command failed: taskkill /pid 16852 /T /F
ERROR: The process "16852" not found.

    at ChildProcess.exithandler (node:child_process:399:12)
    at ChildProcess.emit (node:events:520:28)
    at maybeClose (node:internal/child_process:1092:16)
    at Process.ChildProcess._handle.onexit (node:internal/child_process:302:5) {
  killed: false,
  code: 128,
  signal: null,
  cmd: 'taskkill /pid 16852 /T /F'
}

 โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”โ€”

 >  NX   Running target serve for project nodeapp4 failed

   Failed tasks:

   - nodeapp4:serve:development

   Hint: run the command with --verbose for more details.


C:\my-monorepo-dir>
  • And I'm then sent back to the cmd.exe prompt
  • Therefore I have to manually re-run nx serve or nx build every single time I edit anything

Expected Behavior

  • Don't crash
  • nx serve should just keep running regardless of what taskkill.exe does

GitHub Repo

No response

Steps to Reproduce

All on a Windows machine:

  1. Create a new Node app with command: nx g @nx/node:application nodeapp4 --e2eTestRunner=none
  2. For the "framework" question, pick "none"
  3. Run nx serve nodeapp4
  4. Open apps\nodeapp4\src\main.ts in any basic editor, e.g. Notepad
  5. Hit ctrl+s to save the file, you don't even need to do an edit
  6. nx serve crashes

Nx Report

>  NX   Report complete - copy this into the issue template

   Node   : 16.14.0
   OS     : win32 x64
   npm    : 9.6.5
   Hasher : Native

   nx (global)        : 16.2.2
   nx                 : 16.2.2
   @nx/js             : 16.2.2
   @nx/jest           : 16.2.2
   @nx/linter         : 16.2.2
   @nx/workspace      : 16.2.2
   @nx/cypress        : 16.2.2
   @nx/devkit         : 16.2.2
   @nx/esbuild        : 16.2.2
   @nx/eslint-plugin  : 16.2.2
   @nx/express        : 16.2.2
   @nx/node           : 16.2.2
   @nx/react          : 16.2.2
   @nrwl/tao          : 16.2.2
   @nx/web            : 16.2.2
   @nx/webpack        : 16.2.2
   typescript         : 5.0.4

Failure Logs

No response

Operating System

  • [ ] macOS
  • [ ] Linux
  • [X] Windows
  • [ ] Other (Please specify)

Additional Information

  • Maybe it's related to the exitcode 128 from taskkill.exe? Perhaps some Nx code is not expecting that?
  • I've previously seen such errors appear on screen in previous version of Nx, e.g. v15.* + v16.0.0... but nx serve would still continue to run, rather than just crashing entirely
  • It started crashing entirely when I upgraded from v16.0.0 -> v16.2.1, and persists on v16.2.2

hi2u avatar May 28 '23 08:05 hi2u

I also have this issue. I have several node.js apps that are just scripts that run (no servers or anything to kill).

node:internal/errors:868
  const err = new Error(message);
              ^

Error: Command failed: taskkill /pid 1804 /T /F
ERROR: The process "1804" not found.

    at ChildProcess.exithandler (node:child_process:419:12)
    at ChildProcess.emit (node:events:513:28)
    at maybeClose (node:internal/child_process:1091:16)
    at ChildProcess._handle.onexit (node:internal/child_process:302:5) {
  code: 128,
  killed: false,
  signal: null,
  cmd: 'taskkill /pid 1804 /T /F'
}

znorman-harris avatar May 31 '23 18:05 znorman-harris

I am having this issue as well. Seems to happen more often when I make back to back changes before the processes have been restarted.

In my example:

  1. NestJS app is running
  2. Change made in NestJS app files
  3. File change detected. Restarting...
  4. Quickly make an additional change before the restart is complete
  5. Error: Command failed: Taskkill /pid ##### /T /F

jasonmcleod avatar Jun 02 '23 12:06 jasonmcleod

Same story, error appears after upgrade to 16.3.2.

ivan-shaban avatar Jun 08 '23 10:06 ivan-shaban

Same problem. see #17208

Filoz avatar Jun 14 '23 08:06 Filoz

Any update on this? It's very annoying having to build with "nx build app --watch" and then manually running the node.js script.

znorman-harris avatar Jun 14 '23 16:06 znorman-harris

  • I just upgraded from Nx 16.3.2 -> 16.6.0
  • โœ”๏ธ Looks like this is fixed for my setup
  • Anyone else who was experiencing the issue:
    • Can you please upgrade
    • And confirm back whether it's fixed for you too?

hi2u avatar Aug 10 '23 05:08 hi2u

I can confirm it is working as expected.

However, it is quite slow compared to the past. it was lightning fast for my node + typescript, now it takes 5-10 seconds to work. I'm also not getting all output from my processes being forwarded to the console and am forced to run nx build project --watch and node dist/apps/project/main.js to see what I used to. Waiting to see if this gets fixed magically before reporting.

znorman-harris avatar Aug 10 '23 17:08 znorman-harris

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.

github-actions[bot] avatar Oct 22 '23 00:10 github-actions[bot]