-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Dev server child process cannot be killed #5026
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
The problem is in const { spawn } = require("child_process");
const proc = spawn("webpack", ["serve", "--mode", "development"], { stdio: "inherit" });
setTimeout(() => {
proc.kill();
}, 5000); This is because |
Sorry for the quietness on my part. I was trying to find some time to understand the details behind this and whether there is maybe some npm options to make this work regardless, as it would be convenient to be able to run the That being said, I just tried to reproduce the behavior and it seems like this is not an issue anymore. Node now seems to shut down the npm process and the child webpack process successfully on If this is not the case on your system, you can use the following fix: const find = require("find-process");
// Fix for webpack dev server not being killed by appProcess.kill().
const webpack = await find('port', appPort);
if (webpack.length > 0) {
console.log(`killing ${webpack[0].name}`);
process.kill(webpack[0].pid);
} else {
console.log(`no process listening on ${appPort}`);
} |
Bug report
When spawning the webpack dev server via
child_process.spawn
in a node.js script, the child process cannot be killed viaproc.kill()
. If the parent process is exited viaprocess.exit(0)
, the dev server child process continues running in the background and doesn't free up the bound port.Platform: macOS 14.2.1
Relates to #2168 (comment).
Actual Behavior
proc.kill
does not stop dev server.Expected Behavior
proc.kill
stops dev server.How Do We Reproduce?
Create an npm project with the files below.
Run
npm i
and thennpm run test
.Observe via task manager that the webpack server continues to be running in the background.
package.json
webpack.config.js
test.js
src/index.js
Output of
npx webpack-cli info
The text was updated successfully, but these errors were encountered: