Unitech / pm2

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

Error "Script not found" when running `pm2 start npm -- start` #4811

Open dlinning-jockey opened 4 years ago

dlinning-jockey commented 4 years ago

What's going wrong?

When trying to run a Next.js based site via PM2 through an npm script, the error above is thrown. See output below:

PS C:\Users\Me\Desktop\MyApp> pm2 start npm --name "app" -- start
[PM2] Starting C:\PROGRAM FILES\NODEJS\NPM.CMD in fork_mode (1 instance)               
[PM2] Done.
[PM2][ERROR] Script not found: C:\Users\Me\Desktop\MyApp\start

How could we reproduce this issue?

package.json

{
    "scripts": {
        "start": "next build && next start -p $PORT"
    },
}

Command: pm2 start npm --name "app" -- start

Supporting information

OS: Windows 10 NPM Path:

C:\Program Files\nodejs\npm                                                            
C:\Program Files\nodejs\npm.cmd                                                        
C:\Users\Me\AppData\Roaming\npm\npm
C:\Users\Me\AppData\Roaming\npm\npm.cmd

report.txt

nibman commented 4 years ago

I more or less get the same error whenever I try to give a name to my app... for exemple:

npm start app.js // --> works like a charm

npm start app.js --name myApp // Crashes with Script not found

nibman commented 4 years ago

Well.... solved it by adding a trailing \ after app.js so:

npm start app.js\ --name myApp Now works... hmmm.

heavenkiller2018 commented 4 years ago

@dlinning-jockey ,did you fixed it already?

dlinning-jockey commented 4 years ago

@heavenkiller2018 I have not. This is still a standing bug.

Arnique commented 4 years ago

Still not working.

ghost commented 4 years ago

This is still an issue. There is a workaround for it by giving npm file path in the script . #3657

We are already using pm2 in production. We are trying to change local development to Docker and its not working due to this script issue. I think this is supposed to be a feature which was implemented in #1317 but its failing now.

Can pm2 team take a look please.

gabrielgianesini commented 2 years ago

Hello, Try the following steps: 1º Run one of the following yarn build or npm run build ("next build") 2º Create a file with an extension .json for example "deploy.json": { "apps" : [{ "name" : "Project_name", "script" : "./node_modules/next/dist/bin/next", "env":{ "PORT": "5454" } } ] } 3º Execute the following command pm2 start deploy.json

Hope it helps!

47vigen commented 2 years ago

Hello, Try the following steps: 1º Run one of the following yarn build or npm run build ("next build") 2º Create a file with an extension .json for example "deploy.json": { "apps" : [{ "name" : "Project_name", "script" : "./node_modules/next/dist/bin/next", "env":{ "PORT": "5454" } } ] } 3º Execute the following command pm2 start deploy.json

Hope it helps!

I cant run app in production mode with this solution :)

the-nippy commented 2 years ago

Hello, Try the following steps: 1º Run one of the following yarn build or npm run build ("next build") 2º Create a file with an extension .json for example "deploy.json": { "apps" : [{ "name" : "Project_name", "script" : "./node_modules/next/dist/bin/next", "env":{ "PORT": "5454" } } ] } 3º Execute the following command pm2 start deploy.json

Hope it helps!

it works for me , thanks ! !

but there is still a question , I run 'pm2 start deploy.json', it runs the dev version. if I need to run the build(prod) version, need to edit './node_modules/next/dist/bin/next' file as (line 47) :

 // const defaultCommand = 'dev';   
 const defaultCommand = 'start';
sofyanemakerri commented 2 years ago

You can add start as args in deploy.json file :

"script": "./node_modules/next/dist/bin/next", "args": "start",

csckhw303 commented 1 year ago

I don't think it is working.

scripts: { "start": "next build && next start -p 4000", .... }

deploy.json { "script": "node_module....../bin/next", "args": "start",

}

pm2 start deploy.json is not working but without "args": "start" working with the default port.

talaljavedd commented 1 year ago

Hello, Try the following steps: 1º Run one of the following yarn build or npm run build ("next build") 2º Create a file with an extension .json for example "deploy.json": { "apps" : [{ "name" : "Project_name", "script" : "./node_modules/next/dist/bin/next", "env":{ "PORT": "5454" } } ] } 3º Execute the following command pm2 start deploy.json

Hope it helps!

It worked, thank you so much

sigespweb22 commented 11 months ago

Pra mim resolveu aplicando o comando abaixo. Fazendo a instalação do ts-node npm install -g ts-node

Akbar1909 commented 5 months ago

still this issue is active

marizombie commented 5 months ago

Had same issue Turning command into pm2 start --name name script.js worked for me Hope it helps 👍

MobinAskari commented 2 months ago

This has been an issue since 2020 and it's still not fixed!? This seems like a deal breaker because it made using pm2 a headache for the past couple of hours...