webpack-dev-server: `webpack-dev-server` cannot be killed when spawned with `child_process`

  • Operating System: Windows 10.0.17134 Build 17134
  • Node Version: 8.11.1
  • NPM Version: 5.6.0
  • webpack Version: 4.39.0
  • webpack-dev-server Version: 3.7.2
  • Browser: Not Applicable
  • This is a bug
  • This is a modification request

Expected Behavior

webpack-dev-server should be killed with childProcess.kill() after spawning it with require("child_process").spawn().

Actual Behavior

webpack-dev-server is orphaned instead of being killed in the above scenario.

Steps to Reproduce

Create a folder with the following package.json:

{
  "name": "webpack-dev-server-process-exit-bug-test",
  "dependencies": {
    "webpack": "^4.39.0",
    "webpack-cli": "^3.3.6",
    "webpack-dev-server": "^3.7.2"
  }
}

Add a test.js file:

const { spawn: spawnProcess } = require("child_process");

let devServerProcess = spawnProcess(
  ".\\node_modules\\.bin\\webpack-dev-server", [],
  { shell: true, stdio: "inherit" });

setTimeout(_ => {
  devServerProcess.kill();
  console.log("Trying to kill webpack-dev-server...");
}, 5000);

Add a src.js file to satisfy the webpack zero-config defaults:

console.log("test");

Run npm i then node test.js and check the running processes on your system. The webpack-dev-server node has not been killed as expected.

Note

This issue still occurs when the stdio option is not supplied to the spawn function.

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 5
  • Comments: 25 (10 by maintainers)

Most upvoted comments