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

4.7k views Asked by At

I have installed nodejs that is provided by amazon-extras:

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

Let's install pm2 now:

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
└── [email protected] 

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 [email protected]: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})
npm WARN [email protected] requires a peer of bufferutil@^4.0.1 but none was installed.
npm WARN [email protected] 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
/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?

3

There are 3 answers

0
WestCoastProjects On BEST ANSWER

This is highly likely to be due to the default version of node on amazon linux is like incredibly dated

$ 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.

1
Mahesh Kumar Chopker On

Run compatible pm2 version, this worked for me:

npm install pm2@^3

0
Jonathan C On

The version of node on Amazon Linux is pretty outdated.

Try updating it like this:

sudo npm install n -g
sudo n latest