Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Possible Bug] Ecosystem config refuses to run because it's formatted as an ES Module despite it running fine on another machine #5953

Open
LunarN0v4 opened this issue Feb 16, 2025 · 2 comments

Comments

@LunarN0v4
Copy link

The following ecosystem config refuses to run because it's formatted as an ES Module, but it works fine under my host machine:

export const apps = [
  {
    name: "xivi",
    script: "bun install && bun run build && bun run start",
    interpreter: "none",
    exec_mode: "fork",
    instances: 1,
    autorestart: true,
    watch: false,
    max_memory_restart: "1G",
    env: {
      PATH: `${process.env.HOME}/.bun/bin:${process.env.PATH}`,
    },
  },
];

error on remote machine:

$ pm2 start; pm2 save --force
[PM2][ERROR] File ecosystem.config.js malformated
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/nova/Xivi15/ecosystem.config.js from /home/nova/Xivi15/node_modules/pm2/lib/Common.js not supported.
Instead change the require of ecosystem.config.js in /home/nova/Xivi15/node_modules/pm2/lib/Common.js to a dynamic import() which is available in all CommonJS modules.
    at Common.parseConfig (/home/nova/Xivi15/node_modules/pm2/lib/Common.js:331:12)
    at API._startJson (/home/nova/Xivi15/node_modules/pm2/lib/API.js:934:25)
    at API.start (/home/nova/Xivi15/node_modules/pm2/lib/API.js:329:12)
    at /home/nova/Xivi15/node_modules/pm2/lib/binaries/CLI.js:292:13
    at /home/nova/Xivi15/node_modules/async/internal/withoutIndex.js:8:40 {
  code: 'ERR_REQUIRE_ESM'
}
[PM2] Saving current process list...
[PM2] Successfully saved in /home/nova/.pm2/dump.pm2

on my own machine, heres what happens:

❯ bun run pm2:start
$ pm2 start; pm2 save --force
[PM2] Applying action restartProcessId on app [xivi](ids: [ 0 ])
[PM2] [xivi](0) ✓
┌────┬─────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name    │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├────┼─────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0  │ xivi    │ default     │ N/A     │ fork    │ 361545   │ 0s     │ 1    │ online    │ 0%       │ 5.3mb    │ nova     │ disabled │
└────┴─────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2] Saving current process list...
[PM2] Successfully saved in /home/nova/.pm2/dump.pm2

the only difference between my main machine and the remote machine is my main is on arch linux and the remote is debian 12

@LunarN0v4
Copy link
Author

@LunarN0v4
Copy link
Author

also when fixing it to be CJS compliant:

❯ bun run pm2:start
$ pm2 start; pm2 save --force
[PM2][ERROR] File ecosystem.config.js malformated
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/nova/Xivi15/ecosystem.config.js from /home/nova/Xivi15/node_modules/pm2/lib/Common.js not supported.
ecosystem.config.js is treated as an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which declares all .js files in that package scope as ES modules.
Instead either rename ecosystem.config.js to end in .cjs, change the requiring code to use dynamic import() which is available in all CommonJS modules, or change "type": "module" to "type": "commonjs" in /home/nova/Xivi15/package.json to treat all .js files as CommonJS (using .mjs for all ES modules instead).

    at Common.parseConfig (/home/nova/Xivi15/node_modules/pm2/lib/Common.js:331:12)
    at API._startJson (/home/nova/Xivi15/node_modules/pm2/lib/API.js:934:25)
    at API.start (/home/nova/Xivi15/node_modules/pm2/lib/API.js:329:12)
    at /home/nova/Xivi15/node_modules/pm2/lib/binaries/CLI.js:292:13
    at /home/nova/Xivi15/node_modules/async/internal/withoutIndex.js:8:40 {
  code: 'ERR_REQUIRE_ESM'
}
[PM2] Saving current process list...
[PM2] Successfully saved in /home/nova/.pm2/dump.pm2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant