diff --git a/packages/nx/src/executors/run-commands/running-tasks.ts b/packages/nx/src/executors/run-commands/running-tasks.ts index b3420c0e90..b755969328 100644 --- a/packages/nx/src/executors/run-commands/running-tasks.ts +++ b/packages/nx/src/executors/run-commands/running-tasks.ts @@ -359,21 +359,15 @@ class RunningNodeProcess implements RunningTask { kill(signal?: NodeJS.Signals): Promise { return new Promise((res, rej) => { - if (process.platform === 'win32') { - if (this.childProcess.kill(signal)) { - res(); + treeKill(this.childProcess.pid, signal, (err) => { + // On Windows, tree-kill (which uses taskkill) may fail when the process or its child process is already terminated. + // Ignore the errors, otherwise we will log them unnecessarily. + if (err && process.platform !== 'win32') { + rej(err); } else { - rej('Unable to kill process'); + res(); } - } else { - treeKill(this.childProcess.pid, signal, (err) => { - if (err) { - rej(err); - } else { - res(); - } - }); - } + }); }); }