简体   繁体   English

pm2 生态系统文件 [PM2][错误] 文件./ecosystem.config.js 格式错误

[英]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.

相关问题 Pm2 问题 - 从生态系统.config.js 启动过程时找不到 fs.readfilesync 文件 - Pm2 issue - fs.readfilesync file not found when procces started from ecosystem.config.js 为什么 pm2 忽略了生态系统.config.js 文件中传递给节点的 --experimental-modules ? - Why pm2 ignored the --experimental-modules passed to node in the ecosystem.config.js file? PM2 忽略生态系统文件 - PM2 ignoring ecosystem file PM2 启动生态系统.config.js 在节点 js 项目中的 dockerfile 中不起作用 - PM2 start ecosystem.config.js not working in dockerfile in node js project pm2重新加载Ecosystem.config.js导致应用程序多次重启 - pm2 reload ecosystem.config.js causing many restarts on application 如果我使用 dotenv 和 PM2生态系统.config.js 设置环境变量,Node 将使用哪一个? - If I set env vars using dotenv and PM2 ecosystem.config.js, which one will Node use? pm2 脚本执行路径不正确,与ecosystem.config.js 中的不匹配 - pm2 script execution path is incorrect, doesn't match the one in ecosystem.config.js pm2 不会在重新启动或重新加载时将更改应用于生态系统.config.js - pm2 does not apply changes to ecosystem.config.js on restart or reload 使用生态系统配置文件使用 pm2 运行 express 应用程序时出现问题 - Problem running express app with pm2 using ecosystem config file 使用生态系统 JS 文件设置 PM2 LogRotate - Setup PM2 LogRotate using Ecosystem JS File
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM