Unitech / Unitech/pm2

Running `pm2` installed locally does not work, Global works

Open
#5,137 1 comment 4 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?

I don't know if I am supposed to be able to run pm2 locally (by installing it in a folder as a dev-dependency) and since I didn't find any documentation saying I cannot, I assume I can, however, running pm2-dev(and pm2) on local project installation fails, whereas running it with global installation, it works.

Example

Running

$ yarn global add pm2
$ pm2-dev start pm2-config.json

However if I declare a script on my package.json that has this content:

{ 
  "scripts": {
    "dev": "pm2-dev start pm2-apps.json",
  }
}

and I install pm2 locally like this:

yarn add pm2

then I execute the following, the process does not start

yarn dev
yarn run v1.17.3
$ pm2-dev start pm2-apps.json
===============================================================================
--- PM2 development mode ------------------------------------------------------
Apps started         : aservice
Processes started    : 1
Watch and Restart    : Enabled
Ignored folder       : node_modules
===============================================================================
aservice-0  | /private/var/folders/9l/fh3w0b2s60b5dr_b_b2p1tvh0000gp/T/yarn--1627652469064-0.9997523061209728/yarn:3
aservice-0  | exec "/Users/some.person/.nvm/versions/node/v12.16.2/bin/node" "/Users/some.person/Projects/my-app/bin/yarn.js" "$@"
aservice-0  |      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
aservice-0  | SyntaxError: Unexpected string
aservice-0  |     at wrapSafe (internal/modules/cjs/loader.js:1070:16)
aservice-0  |     at Module._compile (internal/modules/cjs/loader.js:1120:27)
aservice-0  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
aservice-0  |     at Module.load (internal/modules/cjs/loader.js:1000:32)
aservice-0  |     at Function.Module._load (internal/modules/cjs/loader.js:899:14)
aservice-0  |     at Object.<anonymous> (/Users/some.person/Projects/my-app/node_modules/pm2/lib/ProcessContainerFork.js:33:23)
aservice-0  |     at Module._compile (internal/modules/cjs/loader.js:1156:30)
aservice-0  |     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1176:10)
aservice-0  |     at Module.load (internal/modules/cjs/loader.js:1000:32)
aservice-0  |     at Function.Module._load (internal/modules/cjs/loader.js:899:14)

How could we reproduce this issue?

  • Running pm2 through a yarn script

Supporting information

Local

--- PM2 report ----------------------------------------------------------------
Date                 : Fri Jul 30 2021 15:57:57 GMT+0200 (Central European Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.1.0
node version         : 12.16.2
node path            : /Users/some.person/Projects/my-app/node_modules/.bin/pm2
argv                 : /Users/some.person/.nvm/versions/node/v12.16.2/bin/node,/Users/some.person/Projects/my-app/node_modules/pm2/lib/Daemon.js
argv0                : /Users/some.person/.nvm/versions/node/v12.16.2/bin/node
user                 : some.person
uid                  : 502
gid                  : 20
uptime               : 0min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.1.0
node version         : 12.16.2
node path            : /Users/some.person/Projects/my-app/node_modules/.bin/pm2
argv                 : /Users/some.person/.nvm/versions/node/v12.16.2/bin/node,/Users/some.person/Projects/my-app/node_modules/.bin/pm2,report
argv0                : /Users/some.person/.nvm/versions/node/v12.16.2/bin/node
user                 : some.person
uid                  : 502
gid                  : 20
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : darwin
type                 : Darwin
cpus                 : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
cpus nb              : 12
freemem              : 2772164608
totalmem             : 34359738368
home                 : /Users/some.person
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
└─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/Users/some.person/.pm2/pm2.log last 20 lines:
PM2        | 2021-07-30T15:56:03: PM2 log: Concurrent actions   : 2
PM2        | 2021-07-30T15:56:03: PM2 log: SIGTERM timeout      : 1600
PM2        | 2021-07-30T15:56:03: PM2 log: ===============================================================================
PM2        | 2021-07-30T15:57:08: PM2 log: PM2 successfully stopped
PM2        | 2021-07-30T15:57:09: PM2 log: ===============================================================================
PM2        | 2021-07-30T15:57:09: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2        | 2021-07-30T15:57:09: PM2 log: Time                 : Fri Jul 30 2021 15:57:09 GMT+0200 (Central European Summer Time)
PM2        | 2021-07-30T15:57:09: PM2 log: PM2 version          : 5.1.0
PM2        | 2021-07-30T15:57:09: PM2 log: Node.js version      : 12.16.2
PM2        | 2021-07-30T15:57:09: PM2 log: Current arch         : x64
PM2        | 2021-07-30T15:57:09: PM2 log: PM2 home             : /Users/some.person/.pm2
PM2        | 2021-07-30T15:57:09: PM2 log: PM2 PID file         : /Users/some.person/.pm2/pm2.pid
PM2        | 2021-07-30T15:57:09: PM2 log: RPC socket file      : /Users/some.person/.pm2/rpc.sock
PM2        | 2021-07-30T15:57:09: PM2 log: BUS socket file      : /Users/some.person/.pm2/pub.sock
PM2        | 2021-07-30T15:57:09: PM2 log: Application log path : /Users/some.person/.pm2/logs
PM2        | 2021-07-30T15:57:09: PM2 log: Worker Interval      : 30000
PM2        | 2021-07-30T15:57:09: PM2 log: Process dump file    : /Users/some.person/.pm2/dump.pm2
PM2        | 2021-07-30T15:57:09: PM2 log: Concurrent actions   : 2
PM2        | 2021-07-30T15:57:09: PM2 log: SIGTERM timeout      : 1600
PM2        | 2021-07-30T15:57:09: PM2 log: ===============================================================================

Global

--- PM2 report ----------------------------------------------------------------
Date                 : Fri Jul 30 2021 15:59:03 GMT+0200 (Central European Summer Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.1.0
node version         : 12.16.2
node path            : /Users/some.person/Projects/my-app/node_modules/.bin/pm2
argv                 : /Users/some.person/.nvm/versions/node/v12.16.2/bin/node,/Users/some.person/Projects/my-app/node_modules/pm2/lib/Daemon.js
argv0                : /Users/some.person/.nvm/versions/node/v12.16.2/bin/node
user                 : some.person
uid                  : 502
gid                  : 20
uptime               : 1min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.1.0
node version         : 12.16.2
node path            : /usr/local/bin/pm2
argv                 : /Users/some.person/.nvm/versions/node/v12.16.2/bin/node,/usr/local/bin/pm2,report
argv0                : node
user                 : some.person
uid                  : 502
gid                  : 20
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : darwin
type                 : Darwin
cpus                 : Intel(R) Core(TM) i7-9750H CPU @ 2.60GHz
cpus nb              : 12
freemem              : 2873901056
totalmem             : 34359738368
home                 : /Users/some.person
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
└─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs --------------------------------------------
/Users/some.person/.pm2/pm2.log last 20 lines:
PM2        | 2021-07-30T15:56:03: PM2 log: Concurrent actions   : 2
PM2        | 2021-07-30T15:56:03: PM2 log: SIGTERM timeout      : 1600
PM2        | 2021-07-30T15:56:03: PM2 log: ===============================================================================
PM2        | 2021-07-30T15:57:08: PM2 log: PM2 successfully stopped
PM2        | 2021-07-30T15:57:09: PM2 log: ===============================================================================
PM2        | 2021-07-30T15:57:09: PM2 log: --- New PM2 Daemon started ----------------------------------------------------
PM2        | 2021-07-30T15:57:09: PM2 log: Time                 : Fri Jul 30 2021 15:57:09 GMT+0200 (Central European Summer Time)
PM2        | 2021-07-30T15:57:09: PM2 log: PM2 version          : 5.1.0
PM2        | 2021-07-30T15:57:09: PM2 log: Node.js version      : 12.16.2
PM2        | 2021-07-30T15:57:09: PM2 log: Current arch         : x64
PM2        | 2021-07-30T15:57:09: PM2 log: PM2 home             : /Users/some.person/.pm2
PM2        | 2021-07-30T15:57:09: PM2 log: PM2 PID file         : /Users/some.person/.pm2/pm2.pid
PM2        | 2021-07-30T15:57:09: PM2 log: RPC socket file      : /Users/some.person/.pm2/rpc.sock
PM2        | 2021-07-30T15:57:09: PM2 log: BUS socket file      : /Users/some.person/.pm2/pub.sock
PM2        | 2021-07-30T15:57:09: PM2 log: Application log path : /Users/some.person/.pm2/logs
PM2        | 2021-07-30T15:57:09: PM2 log: Worker Interval      : 30000
PM2        | 2021-07-30T15:57:09: PM2 log: Process dump file    : /Users/some.person/.pm2/dump.pm2
PM2        | 2021-07-30T15:57:09: PM2 log: Concurrent actions   : 2
PM2        | 2021-07-30T15:57:09: PM2 log: SIGTERM timeout      : 1600
PM2        | 2021-07-30T15:57:09: PM2 log: ===============================================================================

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

Reproduce the failure by running pm2-dev start pm2-apps.json through the package.json yarn script, comparing it with the global installation. Start at node_modules/pm2/lib/ProcessContainerFork.js and the reported yarn.js command, then verify that a locally installed pm2 can start the configured process without the SyntaxError.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, node.js
Domain
cli
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 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.