简体   繁体   English

PM2没有安装最新版本的nodejs

[英]PM2 not taking the latest version of nodejs installed

Previously, I had node version v0.10.46 installed on my ec2 server. 以前,我的ec2服务器上安装了节点版本v0.10.46 For a recent project, I decided to give pm2 a try and installed pm2 using npm install pm2 -g . 对于最近的项目,我决定尝试pm2并使用npm install pm2 -g

But, pm2 start index.js errored out since the project was using some ES6 syntax with arrow functions and let keyword. 但是, pm2 start index.js错误,因为该项目使用了带箭头函数和let关键字的一些ES6语法。

在此输入图像描述

Therefore, I updated the node version using nvm to latest v6.9.1, which is also the same version which we used for developing on local (windows). 因此,我使用nvm将节点版本更新到最新的v6.9.1,这也是我们在本地(windows)上开发时使用的版本。

However, pm2 start index.js again errored out with the same error: 但是,pm2启动index.js再次出错并出现同样的错误: 在此输入图像描述

pm2 show index hinted that the nodejs version was still not updated. pm2 show index暗示nodejs版本仍未更新。 I removed the old nodejs version, installed pm2 again, still of no avail. 我删除了旧的nodejs版本,再次安装pm2,仍无济于事。

I tried with other methods as well, by using: 我尝试了其他方法,使用:

pm2 start index.js --interpreter=~/.nvm/versions/node/v6.9.1/bin/node

to force pm2 to use the latest installed version of node. 强制pm2使用最新安装的节点版本。 Every single try gave me the same errors with the same version of nodejs. 每一次尝试都给出了相同版本的nodejs相同的错误。 Why is Pm2 not taking the latest version of node and sticking with 0.10.46? 为什么Pm2没有采用最新版本的节点并且坚持使用0.10.46?

If it helps: 如果它有帮助:

which node
~/.nvm/versions/node/v6.9.1/bin/node
which pm2
~/.nvm/versions/node/v6.9.1/bin/pm2

Also, v0.10.46 was NOT installed using nvm. 此外, v0.10.46使用nvm安装v0.10.46。

Edit: Here are the running pm2 daemons, using ps -ef | grep pm2 编辑:这是运行的pm2守护进程,使用ps -ef | grep pm2 ps -ef | grep pm2 : ps -ef | grep pm2

pm2守护进程

Note that ec2-user is the logged in user and I also tried the same with root user. 请注意,ec2-user是登录用户,我也尝试过root用户。 I installed nvm running node v6.9.1 and pm2 as root user as well with no success. 我以root用户身份安装运行节点v6.9.1和pm2的nvm,但没有成功。 I get the same error. 我犯了同样的错误。

NVM allows you to run multiple version of node at a single time (between multiple shells). NVM允许您一次运行多个版本的节点(在多个shell之间)。 This means that when you run nvm use you are using that version of node within the context of that running shell. 这意味着当您运行nvm use您正在该运行shell的上下文中使用该版本的节点。

Given PM2 runs as a daemon, I believe it kicks off its own process which is why it is not using the current nvm selected version. 鉴于PM2作为一个守护进程运行,我相信它会启动它自己的进程,这就是为什么它不使用当前的nvm选择版本。

This GitHub issue shows the usage of the interpreter flag which might be helpful for your specific issue https://github.com/Unitech/pm2/issues/1034 此GitHub问题显示了解释器标志的使用,这可能对您的特定问题有帮助https://github.com/Unitech/pm2/issues/1034


If the actual issue here is with the PM2 process needing to be running a specific NodeJS version, instead of an application PM2 is spawning, restarting the PM2 dameon itself after running the nvm use would have it startup with the current version of Node selected by nvm . 如果此处的实际问题是PM2进程需要运行特定的NodeJS版本,而不是应用程序PM2正在生成,则在运行nvm use后重新启动PM2 nvm use本身将启动nvm选择的当前版本的Node 。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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