Unitech / pm2

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

pm2 start "npm run start" is not working on windows OS #5428

Open devjoemedia opened 2 years ago

devjoemedia commented 2 years ago

pm2 is not running npm script on windows

how do I configure pm2 to run npm scripts on windows operation system

when I run the follow command below is the error I keep getting script not found

$ pm2 start "yarn start"
[PM2][ERROR] Script not found: C:\Users\Joseph\Desktop\simple-server\yarn start
$ pm2 report
--- PM2 report ----------------------------------------------------------------
Date                 : Tue Aug 30 2022 16:46:43 GMT+0000 (Greenwich Mean Time)
===============================================================================
--- Daemon -------------------------------------------------
pm2d version         : 5.2.0
node version         : 14.17.3
node path            : C:/Program Files/nodejs/node
argv                 : C:\Program Files\nodejs\node.exe,C:\ProgramData\npm\npm\node_modules\pm2\lib\Daemon.js
argv0                : node
user                 : undefined
uid                  : N/A
gid                  : N/A
uptime               : 141min
===============================================================================
--- CLI ----------------------------------------------------
local pm2            : 5.2.0
node version         : 14.17.3
node path            : C:/Program Files/nodejs/node
argv                 : C:\Program Files\nodejs\node.exe,C:\ProgramData\npm\npm\node_modules\pm2\bin\pm2,report
argv0                : C:\Program Files\nodejs\node.exe
user                 : Joseph
===============================================================================
--- System info --------------------------------------------
arch                 : x64
platform             : win32
type                 : Windows_NT
cpus                 : Intel(R) Core(TM) i5-4210U CPU @ 1.70GHz
cpus nb              : 4
freemem              : 2891911168
totalmem             : 8489287680
home                 : C:\Users\Joseph
===============================================================================
--- PM2 list -----------------------------------------------
┌─────┬───────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id  │ name      │ namespace   │ version │ mode    │ pid      │ uptime │ ↺    │ status    │ cpu      │ mem      │ user     │ watching │
└─────┴───────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
[PM2][WARN] Current process list is not synchronized with saved list. App server differs. Type 'pm2 save' to synchronize.
===============================================================================
--- Daemon logs --------------------------------------------
C:\Users\Joseph\.pm2\pm2.log last 20 lines:
PM2        | 2022-08-30T15:15:48: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2022-08-30T15:15:48: PM2 log: App [index:0] online
PM2        | 2022-08-30T15:15:51: PM2 log: App [index:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-30T15:15:51: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2022-08-30T15:15:51: PM2 log: App [index:0] online
PM2        | 2022-08-30T15:15:54: PM2 log: App [index:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-30T15:15:54: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2022-08-30T15:15:54: PM2 log: App [index:0] online
PM2        | 2022-08-30T15:15:57: PM2 log: App [index:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-30T15:15:57: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2022-08-30T15:15:57: PM2 log: App [index:0] online
PM2        | 2022-08-30T15:16:00: PM2 log: App [index:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-30T15:16:00: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2022-08-30T15:16:00: PM2 log: App [index:0] online
PM2        | 2022-08-30T15:16:04: PM2 log: App [index:0] exited with code [0] via signal [SIGINT]
PM2        | 2022-08-30T15:16:04: PM2 log: App [index:0] starting in -fork mode-
PM2        | 2022-08-30T15:16:04: PM2 log: App [index:0] online
PM2        | 2022-08-30T15:16:05: PM2 log: Stopping app:index id:0
PM2        | 2022-08-30T15:16:05: PM2 log: App [index:0] exited with code [1] via signal [SIGINT]
PM2        | 2022-08-30T15:16:05: PM2 log: pid=7312 msg=process killed
BenjaminSNMSF commented 1 year ago

Hello,

you can try the solutions from #2808

zetaraku commented 1 year ago

Same here.

It seems that pm2 can't distinguish between file name and command.

ohadcn commented 1 year ago

have you tried

pm2 start yarn -- start

this is pm2 way of spawning a process with parameters

dzlandis commented 1 year ago

Running into this problem. Solution above did not fix the problem.

ohadcn commented 1 year ago

Running into this problem. Solution above did not fix the problem.

what error did you get?

Did you try unseting NODE_CHANNEL_FD before spawning yarn? (e,g: using a shell script?)

dzlandis commented 1 year ago

Running into this problem. Solution above did not fix the problem.

what error did you get?

Did you try unseting NODE_CHANNEL_FD before spawning yarn? (e,g: using a shell script?)

No I have not done that. The resource you provided seems to be referring to python related things. My program does not have any python code. I'm getting the same error as what this original issue shows:

$ pm2 start "yarn start"
[PM2][ERROR] Script not found: C:\Users\Joseph\Desktop\simple-server\yarn start
dzlandis commented 1 year ago

have you tried

pm2 start yarn -- start

this is pm2 way of spawning a process with parameters

It should be noted, when I tried this method, I got the following error:

[PM2] Starting C:\USERS\DZLAN\APPDATA\ROAMING\NPM\YARN.CMD in fork_mode (1 instance)
[PM2] Done.
[PM2][ERROR] Script not found: C:\Users\dzlan\Documents\GitHub\Scriptly\start