webpack-shell-plugin icon indicating copy to clipboard operation
webpack-shell-plugin copied to clipboard

Stop node process(es) on certain port and start again

Open karladler opened this issue 7 years ago • 1 comments

I'm running webpack in watch mode and want to start the node script after the build automatically. To avoid the EADDRINUSE, Address already in use error, I wan't to kill all node processes running on certain port (3001) before I start my script. It works perfect the first time I run it, but after changing anything in code and webPack does a new build, I get an error:

Executing pre-build scripts
 ......./node_modules/webpack-shell-plugin/lib/index.js:168
        throw error;
        ^

Error: Command failed: node ./bin/server.bundle.js
.......
    at ChildProcess.exithandler (child_process.js:211:12)
    at emitTwo (events.js:106:13)
    at ChildProcess.emit (events.js:192:7)
    at maybeClose (internal/child_process.js:890:16)
    at Socket.<anonymous> (internal/child_process.js:334:11)
    at emitOne (events.js:96:13)
    at Socket.emit (events.js:189:7)
    at Pipe._handle.close [as _onclose] (net.js:501:12)

My plugin config looks like this:

plugins.push(new WebpackShellPlugin({
        // kill node process on port 3001 
        onBuildStart: ['lsof -ti:3001 -c node -a | xargs kill'],
        // kill node process on port 3001 and start server
        onBuildEnd: ['lsof -ti:3001 -c node -a | xargs kill', 'node ./bin/server.bundle.js'],  
        dev: false,
        safe: true
    }));

I'm not really sure if this is a problem with the plugin, but running the same command in shell works like a charm.

Edit: same with 'lsof -ti:3001 -c node -a | xargs kill && node ./bin/server.bundle.js' command

karladler avatar Mar 28 '17 09:03 karladler

commenting Line 168 in /lib/index.js in the plugin would fix it for me, but I have no glue what it does :D

  createClass(WebpackShellPlugin, [{
    key: 'puts',
    value: function puts(error, stdout, stderr) {
      if (error) {
        // throw error;
      }
    }
  }, {

karladler avatar Mar 28 '17 10:03 karladler