Skip to content
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

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

Open
karladler opened this issue Mar 28, 2017 · 1 comment
Open

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

karladler opened this issue Mar 28, 2017 · 1 comment

Comments

@karladler
Copy link

karladler commented Mar 28, 2017

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
Copy link
Author

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;
      }
    }
  }, {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant