Skip to content
Advertisement

pm2 Unexpected token import

I have a webserver that works when I use node or nodemon (e.g. “nodemon index.js”). However, when I try to use pm2 (“pm2 start index.js”), I get “SyntaxError: Unexpected token import”. The full error log is below. What am I doing wrong here?

JavaScript

Advertisement

Answer

Hit the same issue.

pm2 released version 4.2.2 which only works with Node 10.x or better, so:

Best solution is to upgrade your node from 9.x to 10.x or better.

In my case I wanted to stick to node 9 so I fixed the version of pm2 to version 4.2.1

I use npm to install pm2 in my Dockerfile:

Changing:

JavaScript

To:

JavaScript

Will fix the issue and allow you to continue working with node 9 and pm2 4.2.1

If you install pm2 in some other way post your install details and I can recommend how to fix.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement