Unitech / Unitech/pm2

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

Open
#5,431 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
43.3k
Forks
2.7k
PR merge metrics
No merged PRs in 30d

Description

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"

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.

Research direction

Start by reproducing the reported pm2 --interpreter=node@16.10.0 start npm -- run start behavior, then trace PM2's interpreter handling for npm scripts. Done means the command uses the requested Node.js version and the reproduction no longer reports the shell's version.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.