Unitech / pm2

Node.js Production Process Manager with a built-in Load Balancer.
https://pm2.keymetrics.io/docs/usage/quick-start/
Other
41.5k stars 2.62k forks source link

`npm run <script>` is not using provided interpreter #5431

Open samuliasmala opened 2 years ago

samuliasmala commented 2 years ago

What's going wrong?

When starting an app in fork mode using npm run command, the Node.JS version from the current shell is used instead of the version provided by the --interpreter parameter.

How could we reproduce this issue?

// package.json
"scripts": {
    "start": "node app.js"
  },

// app.js
console.log('Using Node.JS version ' + process.version);
$ pm2 -v
5.2.0

$ node -v
v16.16.0

$ pm2 start app.js
Using Node.JS version v16.16.0

$ pm2 --interpreter=node@16.10.0 start app.js
Using Node.JS version v16.10.0

$ pm2 --interpreter=node@16.10.0 start npm -- run start
Using Node.JS version v16.16.0

In the last command I was expecting to get the provided version v16.10.0. I'd be happy to create a PR if guided to right direction to solve this. Workarounds are also appreciated.

Supporting information

--- PM2 report ----------------------------------------------------------------
Date                 : Wed Aug 31 2022 16:11:58 GMT+0300 (Eastern European Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.2.0
node version         : 16.16.0
node path            : /home/asmala/.nvm/versions/node/v16.16.0/bin/pm2
argv                 : /home/asmala/.nvm/versions/node/v16.16.0/bin/node,/home/asmala/.nvm/versions/node/v16.16.0/lib/node_modules/pm2/lib/Daemon.js
argv0                : node
user                 : asmala
uid                  : 1000
gid                  : 1000
uptime               : 10min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.2.0
node version         : 16.16.0
node path            : /home/asmala/.nvm/versions/node/v16.16.0/bin/pm2
argv                 : /home/asmala/.nvm/versions/node/v16.16.0/bin/node,/home/asmala/.nvm/versions/node/v16.16.0/bin/pm2,report
argv0                : node
user                 : asmala
uid                  : 1000
gid                  : 1000
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : linux
type                 : Linux
cpus                 : Intel(R) Core(TM) i5-7500 CPU @ 3.40GHz
cpus nb              : 4
freemem              : 24127868928
totalmem             : 40330231808
home                 : /home/asmala
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name   │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
├─────┼────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 0   │ npm    │ default     │ 0.34.0  │ fork    │ 0        │ 0      │ 15   │ errored   │ 0%       │ 0b       │ asmala   │ disabled │
└─────┴────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. App app differs. Type 'pm2 save' to synchronize.
===============================================================================
--- Daemon logs --------------------------------------------
/home/asmala/.pm2/pm2.log last 20 lines:
PM2        | 2022-08-31T16:09:17: PM2 log: App [npm:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-31T16:09:17: PM2 log: App [npm:0] starting in -fork mode-
PM2        | 2022-08-31T16:09:17: PM2 log: App [npm:0] online
PM2        | 2022-08-31T16:09:18: PM2 log: App [npm:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-31T16:09:18: PM2 log: App [npm:0] starting in -fork mode-
PM2        | 2022-08-31T16:09:18: PM2 log: App [npm:0] online
PM2        | 2022-08-31T16:09:18: PM2 log: App [npm:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-31T16:09:18: PM2 log: App [npm:0] starting in -fork mode-
PM2        | 2022-08-31T16:09:18: PM2 log: App [npm:0] online
PM2        | 2022-08-31T16:09:19: PM2 log: App [npm:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-31T16:09:19: PM2 log: App [npm:0] starting in -fork mode-
PM2        | 2022-08-31T16:09:19: PM2 log: App [npm:0] online
PM2        | 2022-08-31T16:09:19: PM2 log: App [npm:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-31T16:09:19: PM2 log: App [npm:0] starting in -fork mode-
PM2        | 2022-08-31T16:09:19: PM2 log: App [npm:0] online
PM2        | 2022-08-31T16:09:20: PM2 log: App [npm:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-31T16:09:20: PM2 log: App [npm:0] starting in -fork mode-
PM2        | 2022-08-31T16:09:20: PM2 log: App [npm:0] online
PM2        | 2022-08-31T16:09:20: PM2 log: App [npm:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-31T16:09:20: PM2 log: Script /home/asmala/.nvm/versions/node/v16.16.0/bin/npm had too many unstable restarts (16). Stopped. "errored"
zhengcaiyunjob commented 2 years ago

how to solve this problem?