Hello,
I am getting this error
When I was run it via simple command "pm2 start test.js"
import express from 'express';
^^^^^^
SyntaxError: Unexpected token import
But if I run it via grunt. Its working fine.
I want to run it via PM2.
I search over google and try to find out reason but I am not satisfied.
Lots of thanks in Advance.
node --experimental-modules my-app.mjs While import is indeed part of ES6, it is unfortunately not yet supported in NodeJS by default, and has only very recently landed support in browsers.
See browser compat table on MDN and this Node issue.
From James M Snell’s Update on ES6 Modules in Node.js (February 2017):
Work is in progress but it is going to take some time — We’re currently looking at around a year at least.
Until support shows up natively, you’ll have to continue using classic require statements:
const express = require("express");
Find Full Source code at here
as Lars Suggested it's not ES6, I think this docs may help http://pm2.keymetrics.io/docs/usage/specifics/
import looks like es6.
Have you checked that pm2 can execute es6 files and not only es5?
That would be my first guess
Peter Scheler
JS enthusiast
importis still not implemented in node. You need to install babel (npm i -g babel-cli) and runpm2 start --interpreter babel-node test.jsinstead.See here.