0

I'm having an error about my ES codes because the babel-node doesn't work when I run the app in pm2 cluster mode, but in fork mode, it run successfully, it says here that --interpreter can't work in cluster mode (-i) due to its operating principle..., so what should I do to run my application that use the latest version of ECMAScript?

My error is

/home/dylan/Projects/project-name/src/index.js:1
import express from 'express'
^^^^^^

SyntaxError: Cannot use import statement outside a module
   ...

My Script

"scripts": {
    ....
    "start": "NODE_ENV=production & pm2 start src --interpreter babel-node -i 2",
    ....
  }
Dylan
  • 1,121
  • 1
  • 13
  • 28

1 Answers1

0

You don't need babel to use import syntax in nodejs. You could enable it in package.json or by using mjs extension. Here is more info about it: https://nodejs.org/api/esm.html#esm_enabling

Serhiy Mamedov
  • 1,080
  • 5
  • 11
  • I am using node13.10 version. I tried both using .mjs file and with type:module both are not working for me. any suggestions? – Sushil Kumar Apr 15 '20 at 06:36