简体   繁体   English

在 amazon linux 上运行 pm2 时出现“语法错误意外令牌...”

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

I have installed nodejs that is provided by amazon-extras :我已经安装了由amazon-extras提供的nodejs

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

Let's install pm2 now:现在让我们安装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.

That seems OK .这似乎没问题。 But then running pm2 is not so happy:但是然后运行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)

What is the issue and workaround for this?这是什么问题和解决方法?

This is highly likely to be due to the default version of node on amazon linux is like incredibly dated这很可能是由于amazon linux上的默认node版本已经过时了

$ node --version
v6.17.1

When I figure out how to get a bronze age (vs stone age) node version this answer will be updated.当我弄清楚如何获得青铜时代(与石器时代)节点版本时,此答案将更新。

Run compatible pm2 version, this worked for me:运行兼容的 pm2 版本,这对我有用:

npm install pm2@^3 npm 安装 pm2@^3

The version of node on Amazon Linux is pretty outdated. Amazon Linux 上的 node 版本已经过时了。

Try updating it like this:尝试像这样更新它:

sudo npm install n -g
sudo n latest

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

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