pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

pm2 start "npm start" doesn't work

Open pols63 opened this issue 3 years ago • 12 comments

Hi:

pm2 start "npm start" doesn't work. I get this error:

[PM2][ERROR] Script not found: D:\Coding\project\npm start

I am using Windows 10. pm2 version 5.2.2

Same error with pm2 start "npm run start"

How execute npm scripts?

Thanks!

pols63 avatar Feb 06 '23 17:02 pols63

try pm2 start npm -- start

abhishekjnvk avatar Feb 13 '23 20:02 abhishekjnvk

try pm2 start npm -- start

Hi. Same error with pm2 start npm -- start

pols63 avatar Feb 14 '23 15:02 pols63

Hi @pols63 can you show us the project or the package.json here?

WillianAgostini avatar Feb 17 '23 03:02 WillianAgostini

Yes, sure:

{
  "name": "test",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "start": "node ."
  },
  "author": "",
  "license": "ISC"
}

I've noted:

  • In the powershell inside VSCode, this commands pm2 start "npm start" and pm2 start npm -- start show this error:
connect EPERM //./pipe/rpc.sock
[PM2] Spawning PM2 daemon with pm2_home=C:\Users\jean.sanchez\.pm2
node:events:491
      throw er; // Unhandled 'error' event
      ^

Error: connect EPERM //./pipe/rpc.sock
    at PipeConnectWrap.afterConnect [as oncomplete] (node:net:1300:16)
Emitted 'error' event on ReqSocket instance at:
    at Socket.<anonymous> (C:\Users\jean.sanchez\AppData\Roaming\npm\node_modules\pm2\node_modules\pm2-axon\lib\sockets\sock.js:201:49)
    at Socket.emit (node:events:513:28)
    at emitErrorNT (node:internal/streams/destroy:151:8)
    at emitErrorCloseNT (node:internal/streams/destroy:116:3)
    at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
  errno: -4048,
  code: 'EPERM',
  syscall: 'connect',
  address: '//./pipe/rpc.sock'
}

Node.js v18.10.0
  • In the Powershell:
pm2 start "npm start"
[PM2][ERROR] Script not found: D:\Coding\test\npm start

pm2 start npm -- start
[PM2] Applying action restartProcessId on app [npm](ids: [ 0 ])
[PM2] [npm](0) ✓
[PM2] Process successfully started
[PM2][ERROR] Script not found: D:\Coding\test\start

Greetings

pols63 avatar Feb 17 '23 13:02 pols63

I'm getting the same issue.

ghost avatar May 15 '23 13:05 ghost

the same to me, and anybody knows why?

rondout avatar Jul 11 '23 10:07 rondout

I had to remember to run it as administrator.

entr0cks avatar Oct 06 '23 19:10 entr0cks

Same here. It works in WSL, but not in Powershell even running as administrator

avenmia avatar Oct 11 '23 06:10 avenmia

I believe this is related to #5763 and how PS handles parameters.

The end-of-parameters token (--) indicates that all arguments following it are to be passed in their actual form as though double quotes were placed around them.

https://learn.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_parsing?view=powershell-7.3#the-end-of-parameters-token

So far, I have not found a way to deal with it. Neither pm2 start npm -- start or pm2 start "npm start" or pm2 start npm "start" or pm2 start npm -- "start" do the trick.

The parameter is always seen as an additional app to be started.

[PM2] Applying action restartProcessId on app [npm](ids: [ 0 ])
[PM2] [npm](0) ✓
[PM2] Process successfully started
[PM2][ERROR] Script not found: C:\test\start

This may go down to:

This behavior only applies to PowerShell commands. If you use the -- token when calling an external command, the -- string is passed as an argument to that command.

martinguenther avatar Mar 26 '24 09:03 martinguenther

How about pm2 start npm -- -- start? The first -- is for powershell, and the second -- is for pm2. It worked for me on windows 11 powershell7.

kimjuls avatar May 17 '24 01:05 kimjuls

Does anyone have any further info on this? I've done my one or two hours of internet searching with no luck.

I attempted @ilovenewts's suggestion, however that didn't seem to work either, so I'm a bit stumped on what else to try.

PM2 v5.4.0 Node.js v18.17.0 OS: Windows Server 2022 Standard v10.0.20348.587

TAEMBO avatar May 25 '24 00:05 TAEMBO

Maybe pm2 start npm -- run start

It helped on a linux server

peacepeacecreation avatar Jul 28 '24 18:07 peacepeacecreation