节点的"/>
为什么pm2忽略了传递给生态系统.config.js文件中节点的
这是我的main.js
文件:
import Koa from "koa";
const app = new Koa();
app.use(async ctx => ctx.body = "Hello, World!");
app.listen(3000);
这是我的package.json
文件:
{
"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 start
现在我需要通过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 start .\ecosystem.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
忽略了--experimental-modules
文件中传递给node
的ecosystem.config.js
?
我看到了类似的问题here,但仍未回答...
回答如下:对于使用esm import
,我正在使用esm package
您可以在文件中添加例如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"
脚本将在没有--experimental-modules
的情况下运行。
正义
"start": "node ./src/index.js"
更多推荐
为什么pm2忽略了传递给生态系统.config.js文件中节点的
发布评论