简体   繁体   中英

PM2 and babel always “Port is in use”

I has been using PM2 to run and monit node process for awhile and it works fine until I try to use babel.

I'm not sure what is the real problem, but when I starting a project with babel, it can't stop showing Port 3000 is already in use .

This project is a copy of another one. They are almost the same except the scripts in package.json .

"scripts": {
    "start": "npm run babel | node ./bin/www",
    "babel": "./node_modules/.bin/babel server -d lib"
}

and the original is much simpler

"scripts": {
    "start": "node ./bin/www"
  }

I use start the process by run process.json , and add "exec_interpreter": "babel-node" in the project with babel.

I also installed some new packages to the copy project including babel, babel-core, babel-loader, react, react-dom, react-hot-loader, webpack and webpack-dev-server. And I changed the code from ES5 to ES6 like that's why I use babel.(yes, I'm trying to use react and transfer to ES6 based on a normal express project)

When I reboot my mac and run the original project without babel, everything is fine. Then I stop the process and go on to start the project with babel, it keep throwing Port 3000 is already in use .

COMMAND    PID  USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
Google     394 brick   14u  IPv6 0x432e592f22d3b26b      0t0  TCP localhost:52261->localhost:hbci (CLOSE_WAIT)
Google     394 brick   16u  IPv6 0x432e592f22d397ab      0t0  TCP localhost:52262->localhost:hbci (CLOSE_WAIT)
Google     394 brick  213u  IPv6 0x432e592f246f87ab      0t0  TCP localhost:52264->localhost:hbci (CLOSE_WAIT)
node      1210 brick   13u  IPv6 0x432e592f22d377ab      0t0  TCP *:hbci (LISTEN)

I use lsof -i:3000 in shell, it shows there's a node process and 2-3 named Google processes(I'm using chrome) is using the port. Even I killed the process, it reappears(with different pid).

I have no idea what's the problem.

Solved this in GitHub. It is indeed the come case babel thing. One of the workarounds is to use babel's require hook in the entry file.

Can read more discussion here: https://github.com/Unitech/pm2/issues/1643

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM