This is my main.js
file:
import Koa from "koa";
const app = new Koa();
app.use(async ctx => ctx.body = "Hello, World!");
app.listen(3000);
This is my package.json
file:
{
"type": "module",
"name": "koa-sandbox",
"version": "1.0.0",
"description": "",
"main": "./src/main.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node --experimental-modules ./src/main.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"koa": "^2.7.0"
}
}
It works fine when I launch it via npm
:
npm start
Now I need to do the same via pm2
. This is my ecosystem.config.js
file:
module.exports = {
apps : [{
name: 'API',
script: './src/main.js',
node_args : '--experimental-modules',
instances: 1,
autorestart: true,
watch: true,
max_memory_restart: '1G',
}],
};
I start my application:
pm2 start .\ecosystem.config.js
but I see the result:
In log-file I see it:
(node:12696) ExperimentalWarning: The ESM module loader is experimental.
C:\lab\koa-sandbox\src\main.js:1
import Koa from "koa";
^^^
SyntaxError: Unexpected identifier
at Module._compile (internal/modules/cjs/loader.js:720:22)
Why pm2
ignored the --experimental-modules
passed to node
in the ecosystem.config.js
file?
I saw similar question here but it hasn't answer still...