TypeError: One of the pids provided is invalid
What's going wrong?
Trying to run a ts script, it doesn't work, but I am sure outside of pm2 works, checking the log the error is:
PM2 | Error caught while calling pidusage
PM2 | TypeError: One of the pids provided is invalid
PM2 | at get (C:\Users\leona\AppData\Roaming\npm\node_modules\pm2\node_modules\pidusage\lib\stats.js:78:23)
PM2 | at pidusage (C:\Users\leona\AppData\Roaming\npm\node_modules\pm2\node_modules\pidusage\index.js:30:5)
PM2 | at Object.getMonitorData (C:\Users\leona\AppData\Roaming\npm\node_modules\pm2\lib\God\ActionMethods.js:60:5)
PM2 | at tasks (C:\Users\leona\AppData\Roaming\npm\node_modules\pm2\lib\Worker.js:150:9)
PM2 | at Domain.
Supporting information
--- PM2 report ----------------------------------------------------------------
Date : Thu Dec 08 2022 00:19:27 GMT+0100 (Central European Standard Time)
===============================================================================
--- Daemon --------------------------------------------------------------------
pm2d version : 5.2.2
node version : 18.12.0
node path : not found
argv : C:\Program Files\nodejs\node.exe,C:\Users\leona\AppData\Roaming\npm\node_modules\pm2\lib\Daemon.js
argv0 : node
user : undefined
uid : N/A
gid : N/A
uptime : 21min
===============================================================================
--- CLI -----------------------------------------------------------------------
local pm2 : 5.2.2
node version : 18.12.0
node path : not found
argv : C:\Program Files\nodejs\node.exe,C:\Users\leona\AppData\Roaming\npm\node_modules\pm2\bin\pm2,report
argv0 : C:\Program Files\nodejs\node.exe
user : dev
===============================================================================
--- System info ---------------------------------------------------------------
arch : x64
platform : win32
type : Windows_NT
cpus : AMD Ryzen 3 3250U with Radeon Graphics
cpus nb : 4
freemem : 816803840
totalmem : 6390263808
home : C:\Users\leona
===============================================================================
--- PM2 list ------------------------------------------------------------------
┌─────┬────────────────┬─────────────┬─────────┬─────────┬──────────┬────────┬──────┬───────────┬──────────┬──────────┬──────────┬──────────┐
│ id │ name │ namespace │ version │ mode │ pid │ uptime │ ↺ │ status │ cpu │ mem │ user │ watching │
├─────┼────────────────┼─────────────┼─────────┼─────────┼──────────┼────────┼──────┼───────────┼──────────┼──────────┼──────────┼──────────┤
│ 1 │ trackPrices │ default │ 1.0.0 │ fork │ N/A │ 6m │ 0 │ online │ 0% │ 0b │ dev │ disabled │
│ 0 │ ts-node │ default │ N/A │ fork │ 0 │ 0 │ 15 │ errored │ 0% │ 0b │ dev │ enabled │
└─────┴────────────────┴─────────────┴─────────┴─────────┴──────────┴────────┴──────┴───────────┴──────────┴──────────┴──────────┴──────────┘
Module
┌────┬──────────────────────────────┬───────────────┬──────────┬──────────┬──────┬──────────┬──────────┬──────────┐
│ id │ module │ version │ pid │ status │ ↺ │ cpu │ mem │ user │
├────┼──────────────────────────────┼───────────────┼──────────┼──────────┼──────┼──────────┼──────────┼──────────┤
│ 2 │ date │ 2.0.2 │ 19416 │ online │ 0 │ 0% │ 0b │ dev │
└────┴──────────────────────────────┴───────────────┴──────────┴──────────┴──────┴──────────┴──────────┴──────────┘
===============================================================================
--- Daemon logs ---------------------------------------------------------------
C:\Users\leona\.pm2\pm2.log last 20 lines:
PM2 | 2022-12-08T00:15:24: PM2 error: Error caught while calling pidusage
PM2 | 2022-12-08T00:15:24: PM2 error: TypeError: One of the pids provided is invalid
PM2 | 2022-12-08T00:15:54: PM2 error: Error caught while calling pidusage
PM2 | 2022-12-08T00:15:54: PM2 error: TypeError: One of the pids provided is invalid
PM2 | 2022-12-08T00:16:24: PM2 error: Error caught while calling pidusage
PM2 | 2022-12-08T00:16:24: PM2 error: TypeError: One of the pids provided is invalid
PM2 | 2022-12-08T00:16:54: PM2 error: Error caught while calling pidusage
PM2 | 2022-12-08T00:16:54: PM2 error: TypeError: One of the pids provided is invalid
PM2 | 2022-12-08T00:17:25: PM2 error: Error caught while calling pidusage
PM2 | 2022-12-08T00:17:25: PM2 error: TypeError: One of the pids provided is invalid
PM2 | 2022-12-08T00:17:55: PM2 error: Error caught while calling pidusage
PM2 | 2022-12-08T00:17:55: PM2 error: TypeError: One of the pids provided is invalid
PM2 | 2022-12-08T00:18:25: PM2 error: Error caught while calling pidusage
PM2 | 2022-12-08T00:18:25: PM2 error: TypeError: One of the pids provided is invalid
PM2 | 2022-12-08T00:18:55: PM2 error: Error caught while calling pidusage
PM2 | 2022-12-08T00:18:55: PM2 error: TypeError: One of the pids provided is invalid
PM2 | 2022-12-08T00:19:25: PM2 error: Error caught while calling pidusage
PM2 | 2022-12-08T00:19:25: PM2 error: TypeError: One of the pids provided is invalid
PM2 | 2022-12-08T00:19:27: PM2 error: Error caught while calling pidusage
PM2 | 2022-12-08T00:19:27: PM2 error: TypeError: One of the pids provided is invalid
I've seen a similar issue, and the cause was in the configuration file, the cwd and/or script commands are executed relative to where pm2 start is run. Once I figured that out I could get the applications to start up.
When I run pm2 start --name myprocessname /path/to/npm/serve/startup/script.js -i 0 -- /serve/path -p [myport] ,and it startup successfully.Then I change the directory name of /serve/path ,and run pm2 stop all then run pm2 start --name myprocessname /path/to/npm/serve/startup/script.js -i 0 -- /serve/path -p [myport] again.I got this Error.At that time,run pm2 describe,will show the value of exec cwd is different from /serve/path which specified in pm2 start command line.I think that's the problem.
any traction on this? I'm having the same issue when trying to run my app via the configuration file
I found this happened when I had nvm running. Here's how I managed to recreate this:
- I had installed an old version of node with
apt-get install nodejs(10.2.0 if you're interested) and installed pm2 on it. I then discovered my new script wouldn't run on this older version so removed nodejs, forgetting to remove pm2. - I had then installed
nvmon my machine, in which I then loaded up v16.2.0 of node. - Then gave
npm i pm2 -ganother go to update it - Encountered this error on run
Managed to fix this one by removing the script, uninstalling pm2 and adding them back on again. Hopefully this is useful! 😀
I've seen a similar issue, and the cause was in the configuration file, the
cwdand/orscriptcommands are executed relative to wherepm2 startis run. Once I figured that out I could get the applications to start up.
Hello, could you be a bit more specific... from "Once I figured that out" doesn't make the steps clear to me to resolve this. 😀
I've seen a similar issue, and the cause was in the configuration file, the
cwdand/orscriptcommands are executed relative to wherepm2 startis run. Once I figured that out I could get the applications to start up.Hello, could you be a bit more specific... from "Once I figured that out" doesn't make the steps clear to me to resolve this. grinning
Not the original poster, but I got around it by changing all relative filepaths to absolute (~/project to /home/ubuntu/project)
I believe this can happen if the contents of your .pm2 directory is somehow stale. If you don't mind setting up from scratch, kill any pm2 processes running on your server, remove the .pm2 directory associated with your pm2 instance, and run all your pm2 start and pm2 save stuff to create the data anew. At least, that kind of scorched earth approach just solved this issue for me. (The other suggestions here didn't work in my case.)
I had this problem (again) just now and rather than removing my .pm2 directory and re-creating it like I did last week, I looked a little closer. There weren't relative paths that were tripping me up like with others, but there was a nonexistent CWD so editing that to be the user's home directory (or whatever, as long as it's a real path) fixed the issue for me. (Probably better, though, to just remove .pm2 and re-create it. Might fix other issues too.)
It's totally understandable that pm2 can't start the process in this case, but it does seem like the program could benefit from better error handling and/or error reporting here.
On my end, I was able to fix this by changing all processes to "cluster" with 1 instance, rather than fork. This seems like a hack, but it got the processes working again.
On my end, I was able to fix this by changing all processes to "cluster" with 1 instance, rather than fork. This seems like a hack, but it got the processes working again.
I got the PID to fill in , but it failed to start and kept it in an error state.
I encountered this problem on windows server 2016, I was able to solved it by. you could try.
- pm2 stop [that process]
- pm2 delete [that process]
- relocate the whole folder of that program to c:[program folder]
- pm2 start that process again from c:[program folder] now I can see the PID. so I know it works.
This seems to only happen when i run a typescript file. My commands for dev and production are exactly the same except for the fact that my dev is reading off typescript. My production start runs fine.
I got the same error with PM2 5.2.2. Updated to 6.0.6 but still getting the same error. Node.js 22.15.0.
In my case the application managed by PM2 was deleted and the process which PM2 tries to find by the process id PM2 stores for each application in <home>/.pm2/pids was not there anymore. From then on PM2 throws the error:
Error caught while calling pidusage
TypeError: One of the pids provided is invalid
So this is not a PM2 error but PM2 could handle that a little bit more gracefull and state in the error message which is the problematic process it cannot find.
Once you know which process is causing this checking the process with pm2 info <your_app> is a good place to analyze the error.
This seems clearly a bug in pm2. Even after rebooting I get this error every few seconds. I have over 50 processes managed by pm2. Anyone with an alternative?