[英]pm2 ecosystem file [PM2][ERROR] File ./ecosystem.config.js malformated
import cfg from 'dotenv-flow';
cfg.config();
const {
HOST_USER,
HOST_DOMAIN,
HOST_PATH,
HOST_PROJECT,
PORT,
VITE_API_ENDPOINT,
APP_URL,
NODE_ENV
} = process.env;
const env_production = {
HOST_USER,
HOST_DOMAIN,
HOST_PATH,
HOST_PROJECT,
PORT,
VITE_API_ENDPOINT,
APP_URL,
NODE_ENV
};
console.log(env_production);
module.exports = {
apps: [
{
name: 'grazily-ui',
script: './build/index.js',
env_production
}
]
};
Getting this error:收到此错误:
┌────┬────────────────────┬──────────┬──────┬───────────┬──────────┬──────────┐
│ id │ name │ mode │ ↺ │ status │ cpu │ memory │
├────┼────────────────────┼──────────┼──────┼───────────┼──────────┼──────────┤
│ 0 │ index │ fork │ 0 │ stopped │ 0% │ 0b │
└────┴────────────────────┴──────────┴──────┴───────────┴──────────┴──────────┘
[PM2][ERROR] File ecosystem.config.js malformated
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/ettinger/www/grazily.com/grazily-ui/ecosystem.config.js from /home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/Common.js not supported.
Instead change the require of ecosystem.config.js in /home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/Common.js to a dynamic import() which is available in all CommonJS modules.
at Object.Common.parseConfig (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/Common.js:317:12)
at API._startJson (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/API.js:934:25)
at API.start (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/API.js:329:12)
at /home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/binaries/CLI.js:290:13
at /home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/node_modules/async/internal/withoutIndex.js:8:40
at replenish (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/node_modules/async/internal/eachOfLimit.js:81:17)
at /home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/node_modules/async/internal/eachOfLimit.js:86:9
at eachLimit (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/node_modules/async/forEachLimit.js:47:43)
at awaitable (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/node_modules/async/internal/awaitify.js:13:28)
at Command.<anonymous> (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/binaries/CLI.js:289:7)
at Command.listener (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/node_modules/commander/index.js:315:8)
at Command.emit (node:events:526:28)
at Command.parseArgs (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/node_modules/commander/index.js:651:12)
at Command.parse (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/node_modules/commander/index.js:474:21)
at beginCommandProcessing (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/binaries/CLI.js:147:13)
at /home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/binaries/CLI.js:221:7
at /home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/API.js:181:16
at /home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/Client.js:54:16
at Timeout._onTimeout (/home/ettinger/.nvm/versions/node/v17.5.0/lib/node_modules/pm2/lib/Client.js:372:9) {
code: 'ERR_REQUIRE_ESM'
}
edit: I opted to just use systemd with a bash script running node index.js
编辑:我选择只使用 systemd 和运行
node index.js
的 bash 脚本
You should rename the file ecosystem.config.js
to ecosystem.config.cjs
when using es module ( "type": "module"
in pacakge.json
)使用 es 模块时应将文件
ecosystem.config.js
系统.config.js 重命名为生态ecosystem.config.cjs
.config.cjs ( "type": "module"
in pacakge.json
)
Use const cfg = require('dotenv-flow')使用 const cfg = require('dotenv-flow')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.