多个NPM和NodeJS版本导致安装PM2 Profiler的SSL /证书问题

时间:2018-07-20 10:46:13

标签: node.js npm pm2

我已经自己解决了这个问题,但是从网上获得的其他答案并没有太大帮助,所以我认为我将在这里发布答案给其他可能遇到相同问题的人。

尝试安装PM2分析器以找出导致NodeJS应用程序内存泄漏的原因,但是在安装过程中出现以下错误:

$ pm2 install profiler
[PM2][Module] Installing module profiler
[PM2][Module] Calling [NPM] to install v8-profiler-node8 ...
npm ERR! Error: CERT_UNTRUSTED
npm ERR!     at SecurePair.<anonymous> (tls.js:1430:32)
npm ERR!     at SecurePair.emit (events.js:92:17)
npm ERR!     at SecurePair.maybeInitFinished (tls.js:1029:10)
npm ERR!     at CleartextStream.read [as _read] (tls.js:521:13)
npm ERR!     at CleartextStream.Readable.read (_stream_readable.js:341:10)
npm ERR!     at EncryptedStream.write [as _write] (tls.js:418:25)
npm ERR!     at doWrite (_stream_writable.js:226:10)
npm ERR!     at writeOrBuffer (_stream_writable.js:216:5)
npm ERR!     at EncryptedStream.Writable.write (_stream_writable.js:183:11)
npm ERR!     at write (_stream_readable.js:602:24)
npm ERR! If you need help, you may report this log at:
npm ERR!     <http://github.com/isaacs/npm/issues>
npm ERR! or email it to:
npm ERR!     <npm-@googlegroups.com>

npm ERR! System Linux 2.6.32-696.20.1.el6.x86_64
npm ERR! command "node" "/usr/bin/npm" "install" "v8-profiler-node8" "--loglevel=error"
npm ERR! cwd /usr/lib/node_modules/pm2
npm ERR! node -v v0.10.48
npm ERR! npm -v 1.3.6
npm ERR!
npm ERR! Additional logging details can be found in:
npm ERR!     /usr/lib/node_modules/pm2/npm-debug.log
npm ERR! not ok code 0
[PM2][Module][ERROR] Profiling installation has FAILED (checkout previous logs)
[PM2][ERROR] Module install failed

网上有很多帖子建议更改NPM设置以忽略证书或忽略https,但这无济于事:

https://stackoverflow.com/a/45884819/884842 https://github.com/nodejs/node/issues/3742#issuecomment-155545828

这是在运行CentOS 6.10的服务器上

1 个答案:

答案 0 :(得分:1)

安装中的错误与SSL证书有关,但这有点误导。尽管具体错误是由于不受信任的SSL证书引起的,但实际上是因为PM2安装过程中使用的NodeJS和NPM的版本较旧,它们使用了过时的证书。

在错误中,您可以认为NodeJS和NPM版本很旧:

npm ERR! node -v v0.10.48
npm ERR! npm -v 1.3.6

但是,当我在命令行上检查NodeJS和NPM版本时,它们是较新的:

$ node -v
v7.6.0
$ npm -v
4.1.2

在安装NPM软件包,更新NodeJS / NPM之前,我已经看到了类似的问题,但是在这种情况下,据我所知,我 did 拥有一个更新版本的NodeJS和NPM,与PM2安装程序要使用的相比。

这里的关键是查看错误日志并发现错误:

npm ERR! command "node" "/usr/bin/npm" "install" "v8-profiler-node8" "--loglevel=error"

具体来说,/usr/bin/npm

PM2正在使用/usr/bin文件夹中的NPM(我假设是NodeJS),但是当我使用which命令时...

$ which node
/usr/local/bin/node
$ which npm
/usr/local/bin/npm

...我们可以看到PM2所在的位置没有安装较新的版本(7.6.0和4.1.2)。

当我设置此服务器时,我可能手动安装了NodeJS和NPM,这要早于NodeJS发行之前。

从那时起,我就使用NVM [https://github.com/creationix/nvm]安装较新的版本。

现在我不知道我的解决方案是否是解决此问题的最佳方法,但它对我有用。 我删除了/usr/bin中的NodeJS和NPM安装,并添加了指向新/usr/local/bin版本的符号链接。

# check we're in the /usr/bin folder
$ pwd 
/usr/bin

#######################
# SORTING OUT NPM FIRST
#######################

# npm version in the bash environment
$ npm -v 
4.1.2

# npm version for the install at /usr/bin/npm
$ ./npm -v
1.3.6

# get rid of the version here in /usr/bin and add link back to the /usr/local/bin version
$ sudo rm npm
$ sudo ln -s /usr/local/bin/npm npm

# npm version in the bash environment
$ npm -v
4.1.2

# npm version for the install at /usr/bin/npm - now linking to the newer one
$ ./npm -v
4.1.2

##################
# SORTING OUT NODE
##################

# node version in the bash environment
$ node -v
v7.6.0

# node version for the install at /usr/bin/node
$ ./node -v
v0.10.48

# get rid of the version here in /usr/bin and add link back to the /usr/local/bin version
$ sudo rm node
$ sudo ln -s /usr/local/bin/node node

$ node -v
v7.6.0

$ ./node -v
v7.6.0

实际上我是先执行Node的,但并没有帮助(这是UNABLE_TO_GET_ISSUER_CERT_LOCALLY而不是CERT_UNTRUSTED的稍微不同的证书错误,然后我整理了NPM。

您也许可以通过整理NPM安装来做到这一点,但是我做了Node,然后NPM和PM2分析器现在已成功安装,所以这就是我要给出的答案。