Javascript 为什么pm2忽略了生态系统.config.js文件中传递给节点的--experimental模块?
这是我的Javascript 为什么pm2忽略了生态系统.config.js文件中传递给节点的--experimental模块?,javascript,node.js,pm2,es6-modules,Javascript,Node.js,Pm2,Es6 Modules,这是我的main.js文件: import Koa from "koa"; const app = new Koa(); app.use(async ctx => ctx.body = "Hello, World!"); app.listen(3000); { "type": "module", "name": "koa-sandbox", "version": "1.0.0", "description": "", "main": "./src/main.js",
main.js
文件:
import Koa from "koa";
const app = new Koa();
app.use(async ctx => ctx.body = "Hello, World!");
app.listen(3000);
{
"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"
}
}
这是我的package.json
文件:
import Koa from "koa";
const app = new Koa();
app.use(async ctx => ctx.body = "Hello, World!");
app.listen(3000);
{
"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"
}
}
当我通过npm
启动它时,它工作正常:
npm启动
现在我需要通过pm2做同样的事情。这是我的ecosystem.config.js
文件:
module.exports = {
apps : [{
name: 'API',
script: './src/main.js',
node_args : '--experimental-modules',
instances: 1,
autorestart: true,
watch: true,
max_memory_restart: '1G',
}],
};
我启动我的应用程序:
pm2启动。\economy.config.js
但我看到了结果:
在日志文件中,我看到它:
(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)
为什么pm2
忽略了生态系统.config.js
文件中传递给节点的--实验模块
我看到了类似的问题,但仍然没有答案 用于使用esmimport
s我正在使用的
您可以在文件中添加文件,例如index.js
require = require("esm")(module/*, options*/)
module.exports = require("./main.js")
并将ecosystem.config.js
修改为
module.exports = {
apps : [{
name: 'API',
script: './src/index.js',
instances: 1,
autorestart: true,
watch: true,
max_memory_restart: '1G',
}],
};
在package.json中,您不必
"start": "node --experimental-modules ./src/main.js"
脚本将在没有实验模块的情况下运行
只是