pm2 startup fails to start Nuxt app, only pm2 resurrect works. Please help getting nuxt to run on startup! ERR_REQUIRE_ESM
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 43.3k
- Forks
- 2.7k
- PR merge metrics
- No merged PRs in 30d
Description
Hi. I am beating all the day with nuxt and pm2
This works:
su user
user@aet:$ pm2 status$ pm2 resurrect
[PM2] Spawning PM2 daemon with pm2_home=/home/user/.pm2
[PM2] PM2 Successfully daemonized
┌────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
└────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. App NuxtAppName NuxtAppName strapi-dev differs. Type 'pm2 save' to synchronize.
user@aet:
[PM2] Resurrecting
[PM2] Restoring processes located in /home/user/.pm2/dump.pm2
[PM2] Process /home/user/.output/server/index.js restored
[PM2] Process /home/user/.output/server/index.js restored
[PM2] Process /home/user/.nvm/versions/node/v20.18.1/bin/npm restored
┌────┬────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├────┼────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0 │ NuxtAppName │ default │ 0.0.0 │ cluster │ 1017 │ 0s │ 0 │ online │ 0% │ 45.9mb │ user │ disabled │
│ 1 │ NuxtAppName │ default │ 0.0.0 │ cluster │ 1018 │ 0s │ 0 │ online │ 0% │ 45.6mb │ user │ disabled │
│ 2 │ strapi-dev │ default │ 0.39.5 │ fork │ 1031 │ 0s │ 0 │ online │ 0% │ 43.7mb │ user │ disabled │
└────┴────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
if I enable pm2-startup, the app NuxtAppName get into error loop
0|NuxtAppN | Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /home/user/.output/server/index.js
0|NuxtAppN | at Object.Module._extensions..js (internal/modules/cjs/loader.js:1015:13)
0|NuxtAppN | at Module.load (internal/modules/cjs/loader.js:863:32)
0|NuxtAppN | at Function.Module._load (internal/modules/cjs/loader.js:708:14)
0|NuxtAppN | at /usr/local/lib/node_modules/pm2/lib/ProcessContainer.js:304:25
0|NuxtAppN | at wrapper (/usr/local/lib/node_modules/pm2/node_modules/async/internal/once.js:12:16)
0|NuxtAppN | at next (/usr/local/lib/node_modules/pm2/node_modules/async/waterfall.js:96:20)
0|NuxtAppN | at /usr/local/lib/node_modules/pm2/node_modules/async/internal/onlyOnce.js:12:16
0|NuxtAppN | at WriteStream. (/usr/local/lib/node_modules/pm2/lib/Utility.js:186:13)
0|NuxtAppN | at WriteStream.emit (events.js:314:20)
0|NuxtAppN | at internal/fs/streams.js:366:10
I tried to do dirty fix, like creating a bash script, that runs 'pm2 status; pm2 resurrect' as user, but it also fails with same error!
Ok, maybe it's systemd problem I thought. Ok created a cron script and run as user... The same! This error loop. Before the script was named index.mjs, I found somewhere to try to create index.js which imports mjs. not helped.
only running a normal 'user' shell session and running commands pm2 status and pm2 resurrect starts this NuxtApp and it works
/home/user/.pm2/logs/NuxtAppName-out-1.log last 15 lines:
0|NuxtAppN | Clien:
0|NuxtAppN | Cookie: undefined
0|NuxtAppN | User: null
0|NuxtAppN | User: undefined
0|NuxtAppN | Client IP:
0|NuxtAppN | Clien:
0|NuxtAppN | Cookie: undefined
0|NuxtAppN | User: null
0|NuxtAppN | useAuth: null
0|NuxtAppN | User: undefined
0|NuxtAppN | Client IP:
0|NuxtAppN | Clien:
0|NuxtAppN | Cookie: undefined
0|NuxtAppN | User: null
0|NuxtAppN | Listening on http://0.0.0.0:3000
How to fix? Please help
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing the pm2 startup path with the successful pm2 resurrect path, using the reported /usr/local/lib/node_modules/pm2/lib/ProcessContainer.js stack and the generated .output/server/index.js entry point. Reproduce the ERR_REQUIRE_ESM loop and determine why startup loads the Nuxt server differently; done means the app starts on boot without the error and behaves like resurrect.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, nodejs, nuxtjs
- Domain
- cli, devops
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100