pm2 not working with experimental-modules flag

时光怂恿深爱的人放手 提交于 2019-12-04 11:44:25

问题


I am using ES6 modules by adding the --experimental-modules arguments to Node. Running node --experimental-modules app.mjs works perfectly fine. However, when I run the same command with pm2 I get the following error:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

My current pm2 config file looks like this:

"apps": [
 {
  "name": "api",
  "script": "app.mjs",
  "exec_mode": "cluster",
  "instances": "max",
  "node_args": "--experimental-modules",
  "env": {
    variables here..
  }
 }
],

I have also tried using esm instead like this:

"node_args": "-r esm"

In both cases they return the same [ERR_REQUIRE_ESM] error


Does anyone have a solution on how to use es6 modules with pm2 or is it broken at the moment?


回答1:


A workaround for this problem:

  • In your package.json file, add a new script:

  "scripts": {
    //Add this one:
    "safestart":"node --experimental-modules app.mjs"
  },
  • Run this PM2 command:

pm2 start npm -- run safestart


来源:https://stackoverflow.com/questions/52499715/pm2-not-working-with-experimental-modules-flag

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!