PM2 won't start app in cluster mode

Open
#5,226 0 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
javascript, node.js
Domain
cli, devops

Research direction

Reproduce the issue with a simple Express app and pm2 start index.js -i 0 on Windows. Start at lib/ProcessContainer.js:301, where the reported ESM URL error occurs. Done means cluster-mode processes can serve the GET route without the ERR_UNSUPPORTED_ESM_URL_SCHEME error.

Written by the indexing model from the issue text.

Description

What's going wrong?

Can't run my app in cluster mode but runs fine in fork mode. Looks like the api is running, however when I try to call the API it can't connect even though PM2 says all processes from the cluster are online.

How could we reproduce this issue?

Build a simple express app with one GET route and then run "pm2 start index.js -i 0"
The processes will start however an error will be logged to the error log and the API will be unreachable

Supporting information

The error, looks to be something to do with windows possibly prefixing paths with 'c:'
I should note all the imports in my apps are relative.

0|index    |     at C:\Users\lukey\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainer.js:301:26
0|index    |     at wrapper (C:\Users\lukey\AppData\Roaming\npm\node_modules\pm2\node_modules\async\internal\once.js:12:16)
0|index    |     at next (C:\Users\lukey\AppData\Roaming\npm\node_modules\pm2\node_modules\async\waterfall.js:96:20)
0|index    | You have triggered an unhandledRejection, you may have forgotten to catch a Promise rejection:
0|index    | Error [ERR_UNSUPPORTED_ESM_URL_SCHEME]: Only file and data URLs are supported by the default ESM loader. On Windows, absolute paths must be valid file:// URLs. Received protocol 'c:'
0|index    |     at new NodeError (internal/errors.js:322:7)
0|index    |     at Loader.defaultResolve [as _resolve] (internal/modules/esm/resolve.js:814:11)
0|index    |     at Loader.resolve (internal/modules/esm/loader.js:89:40)
0|index    |     at Loader.getModuleJob (internal/modules/esm/loader.js:242:28)
0|index    |     at Loader.import (internal/modules/esm/loader.js:177:28)
0|index    |     at importModuleDynamically (internal/modules/cjs/loader.js:1028:27)
0|index    |     at exports.importModuleDynamicallyCallback (internal/process/esm_loader.js:30:14)
0|index    |     at C:\Users\lukey\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainer.js:301:26
0|index    |     at wrapper (C:\Users\lukey\AppData\Roaming\npm\node_modules\pm2\node_modules\async\internal\once.js:12:16)   
0|index    |     at next (C:\Users\lukey\AppData\Roaming\npm\node_modules\pm2\node_modules\async\waterfall.js:96:20)
--- PM2 report ----------------------------------------------------------------
Date                 : Thu Nov 18 2021 18:53:53 GMT+0000 (Greenwich Mean Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.1.2
node version         : 14.18.1
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\lukey\AppData\Roaming\npm\node_modules\pm2\lib\Daemon.js     
argv0                : node
user                 : undefined
uid                  : N/A
gid                  : N/A
uptime               : 4min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.1.2
node version         : 14.18.1
node path            : not found
argv                 : C:\Program Files\nodejs\node.exe,C:\Users\lukey\AppData\Roaming\npm\node_modules\pm2\bin\pm2,report    
argv0                : C:\Program Files\nodejs\node.exe
user                 : lukey
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : win32
type                 : Windows_NT
cpus                 : Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
cpus nb              : 8
freemem              : 3118878720
totalmem             : 17001664512
home                 : C:\Users\lukey
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬──────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name     │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼──────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ index    │ default     │ 1.0.0   │ cluster │ 39528    │ 4m     │ 0    │ online    │ 0%       │ 32.3mb   │ lukey    │ disabled │
│ 1   │ index    │ default     │ 1.0.0   │ cluster │ 4896     │ 4m     │ 0    │ online    │ 0%       │ 32.6mb   │ lukey    │ disabled │
│ 2   │ index    │ default     │ 1.0.0   │ cluster │ 21568    │ 4m     │ 0    │ online    │ 0%       │ 32.6mb   │ lukey    │ disabled │
│ 3   │ index    │ default     │ 1.0.0   │ cluster │ 22880    │ 4m     │ 0    │ online    │ 0%       │ 32.4mb   │ lukey    │ disabled │
│ 4   │ index    │ default     │ 1.0.0   │ cluster │ 35912    │ 4m     │ 0    │ online    │ 0%       │ 32.3mb   │ lukey    │ disabled │
│ 5   │ index    │ default     │ 1.0.0   │ cluster │ 16236    │ 4m     │ 0    │ online    │ 0%       │ 32.3mb   │ lukey    │ disabled │
│ 6   │ index    │ default     │ 1.0.0   │ cluster │ 16080    │ 4m     │ 0    │ online    │ 0%       │ 32.3mb   │ lukey    │ disabled │
│ 7   │ index    │ default     │ 1.0.0   │ cluster │ 10268    │ 4m     │ 0    │ online    │ 0%       │ 32.4mb   │ lukey    │ disabled │
└─────┴──────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
C:\Users\lukey\.pm2\pm2.log last 20 lines:
PM2        | 2021-11-18T18:49:49: PM2 log: Process dump file    : C:\Users\lukey\.pm2\dump.pm2
PM2        | 2021-11-18T18:49:49: PM2 log: Concurrent actions   : 2
PM2        | 2021-11-18T18:49:49: PM2 log: SIGTERM timeout      : 1600
PM2        | 2021-11-18T18:49:49: PM2 log: ===============================================================================    
PM2        | 2021-11-18T18:49:50: PM2 log: App [index:0] starting in -cluster mode-
PM2        | 2021-11-18T18:49:50: PM2 log: App [index:0] online
PM2        | 2021-11-18T18:49:50: PM2 log: App [index:1] starting in -cluster mode-
PM2        | 2021-11-18T18:49:50: PM2 log: App [index:1] online
PM2        | 2021-11-18T18:49:50: PM2 log: App [index:2] starting in -cluster mode-
PM2        | 2021-11-18T18:49:50: PM2 log: App [index:2] online
PM2        | 2021-11-18T18:49:50: PM2 log: App [index:3] starting in -cluster mode-
PM2        | 2021-11-18T18:49:50: PM2 log: App [index:3] online
PM2        | 2021-11-18T18:49:50: PM2 log: App [index:4] starting in -cluster mode-
PM2        | 2021-11-18T18:49:50: PM2 log: App [index:4] online
PM2        | 2021-11-18T18:49:50: PM2 log: App [index:5] starting in -cluster mode-
PM2        | 2021-11-18T18:49:51: PM2 log: App [index:5] online
PM2        | 2021-11-18T18:49:51: PM2 log: App [index:6] starting in -cluster mode-
PM2        | 2021-11-18T18:49:51: PM2 log: App [index:6] online
PM2        | 2021-11-18T18:49:51: PM2 log: App [index:7] starting in -cluster mode-
PM2        | 2021-11-18T18:49:51: PM2 log: App [index:7] online
Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from Unitech/pm2

All issues in Unitech/pm2

Similar issues

More JavaScript issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.