[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2 错误

pm2不管执行什么代码都导致:[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2

[root@iZm5ed3dvbh9bybh81mwcfZ ~]# pm2 list

[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2

[root@iZm5ed3dvbh9bybh81mwcfZ ~]#  

/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)
/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)
/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)
/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)
/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)
/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)
/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)
/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)
/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)
/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)
/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)
/usr/local/node-v6/lib/node_modules/pm2/node_modules/chokidar/index.js:151
  async remove(item) {
        ^^^^^^
SyntaxError: Unexpected identifier
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:542:28)
    at Object.Module._extensions..js (module.js:579:10)
    at Module.load (module.js:487:32)
    at tryModuleLoad (module.js:446:12)
    at Function.Module._load (module.js:438:3)
    at Module.require (module.js:497:17)
    at require (internal/module.js:20:19)
    at Object. (/usr/local/node-v6/lib/node_modules/pm2/lib/Watcher.js:6:16)

出错原因是nodejs版本太低了,需要更新nodejs的版本 

1、安装新版本的node、npm,我选择的是v10.13.0

//下载nodejs安装文件node-v10.13.0-linux-x64.tar.xz
~$ wget https://npm.taobao.org/mirrors/node/v10.13.0/node-v10.13.0-linux-x64.tar.xz

//解压下载的文件
~$ tar -xvf node-v10.13.0-linux-x64.tar.xz

//测试是否安装成功
~$ cd node-v10.13.0-linux-x64/bin && ls
node  npm  npx

//符号./的意思是当前文件夹下,现在 node 和 npm 还不能全局使用
~/node-v10.13.0-linux-x64/bin$ ./node -v
v10.13.0

[root@iZm5ed3dvbh9bybh81mwcfZ ~]# cd node-v10.13.0-linux-x64/bin && ls
node  npm  npx
[root@iZm5ed3dvbh9bybh81mwcfZ bin]# ./node -v
v10.13.0

2、查看当前目录
[root@iZm5ed3dvbh9bybh81mwcfZ bin]# pwd
/root/node-v10.13.0-linux-x64/bin

3、全局使用node、npm
现在npm、node只能在我们刚刚安装的node-v10.13.0-linux-x64/bin文件夹下面使用,我们在Ubuntu中设置环境变量,从而可以全局使用node、npm

[root@iZm5ed3dvbh9bybh81mwcfZ bin]# cd ~
[root@iZm5ed3dvbh9bybh81mwcfZ ~]# vim .bashrc

4、编辑.bashrc文件
vim是一个文本编辑器,输入i,进入编辑状态,添加下面语句
其中/root/node-v10.13.0-linux-x64/bin/是【(2)查看当前目录】中查出来的目录,替换成你自己查到的目录,添加以下内容:

export PATH=/root/node-v10.13.0-linux-x64/bin/:$PATH

5、使环境变量生效
[root@iZm5ed3dvbh9bybh81mwcfZ ~]# source .bashrc

6、检查是否可以全局使用node、npm
[root@iZm5ed3dvbh9bybh81mwcfZ ~]# node -v
v10.13.0
[root@iZm5ed3dvbh9bybh81mwcfZ ~]# npm -v
6.4.1

7、更新完node之后,检查pm2是否可以正常使用
[root@iZm5ed3dvbh9bybh81mwcfZ ~]# pm2 -v
[PM2] Spawning PM2 daemon with pm2_home=/root/.pm2
[PM2] PM2 Successfully daemonized
4.2.3
[root@iZm5ed3dvbh9bybh81mwcfZ ~]# 


参考以下内容:https://blog.csdn.net/shine_a/article/details/102669471

你可能感兴趣的:(Centos)