[英]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. 我已经使用PM2运行和监视节点进程已有一段时间了,在我尝试使用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
. 我不确定真正的问题是什么,但是当我使用babel启动项目时,它无法停止显示
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
. 除了
package.json
的scripts
外,它们几乎相同。
"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. 我使用
run process.json
来run process.json
,并在项目中使用babel添加"exec_interpreter": "babel-node"
。
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. 我还为复制项目安装了一些新软件包,包括babel,babel-core,babel-loader,react,react-dom,react-hot-loader,webpack和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)
我将代码从ES5更改为ES6,这就是我使用babel的原因(是的,我正在尝试使用react并根据正常的快速项目转移到ES6)
When I reboot my mac and run the original project without babel, everything is fine. 当我重新启动Mac并运行没有babel的原始项目时,一切都很好。 Then I stop the process and go on to start the project with babel, it keep throwing
Port 3000 is already in use
. 然后,我停止该过程,并继续使用babel启动该项目,该项目将继续抛出
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. 我在外壳中使用
lsof -i:3000
,它显示有一个节点进程,并且2-3个名为Google进程(我正在使用chrome)正在使用该端口。 Even I killed the process, it reappears(with different pid). 即使我终止了该过程,它也会重新出现(具有不同的pid)。
I have no idea what's the problem. 我不知道出什么问题了。
Solved this in GitHub. 在GitHub中解决了这个问题。 It is indeed the come case babel thing.
的确是案例通天塔。 One of the workarounds is to use babel's require hook in the entry file.
解决方法之一是在条目文件中使用babel的require钩子 。
Can read more discussion here: https://github.com/Unitech/pm2/issues/1643 可以在这里阅读更多讨论: https : //github.com/Unitech/pm2/issues/1643
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.