"Syntax error unexpected token ..." 当 运行 亚马逊上的 pm2 linux

"Syntax error unexpected token ..." when running pm2 on amazon linux

我已经安装了 nodejsamazon-extras:

提供的
sudo amazon-linux-extras install -y epel
yum install -y nodejs
node --version

让我们现在安装pm2

sudo npm install pm2@latest -g

/usr/bin/pm2 -> /usr/lib/node_modules/pm2/bin/pm2
/usr/bin/pm2-dev -> /usr/lib/node_modules/pm2/bin/pm2-dev
/usr/bin/pm2-docker -> /usr/lib/node_modules/pm2/bin/pm2-docker
/usr/bin/pm2-runtime -> /usr/lib/node_modules/pm2/bin/pm2-runtime
/usr/lib
└── pm2@4.5.0 

npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@~2.1.2 (node_modules/pm2/node_modules/chokidar/node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.3: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN ws@7.2.5 requires a peer of bufferutil@^4.0.1 but none was installed.
npm WARN ws@7.2.5 requires a peer of utf-8-validate@^5.0.2 but none was installed.

这似乎还可以。不过后来运行pm2就没那么开心了:

$ pm2
/usr/lib/node_modules/pm2/node_modules/chalk/source/index.js:103
    ...styles,
    ^^^
SyntaxError: Unexpected token ...
    at createScript (vm.js:56:10)
    at Object.runInThisContext (vm.js:97:10)
    at Module._compile (module.js:549:28)
    at Object.Module._extensions..js (module.js:586:10)
    at Module.load (module.js:494:32)
    at tryModuleLoad (module.js:453:12)
    at Function.Module._load (module.js:445:3)
    at Module.require (module.js:504:17)
    at require (internal/module.js:20:19)
    at Object.<anonymous> (/usr/lib/node_modules/pm2/constants.js:10:14)

这是什么问题和解决方法?

这很可能是因为 amazon linuxnode 的默认版本非常过时

$ node --version
v6.17.1

当我弄清楚如何获得青铜时代(vs 石器时代)节点版本时,这个答案将会更新。

运行 兼容的 pm2 版本,这对我有用:

npm 安装 pm2@^3

Amazon 上的节点版本 Linux 已经过时了。

尝试像这样更新它:

sudo npm install n -g
sudo n latest