pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

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

Open dlinning-jockey opened this issue 5 years ago • 16 comments

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

dlinning-jockey avatar Aug 14 '20 16:08 dlinning-jockey

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 avatar Sep 10 '20 00:09 nibman

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

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

nibman avatar Sep 10 '20 00:09 nibman

@dlinning-jockey ,did you fixed it already?

heavenkiller2018 avatar Sep 11 '20 08:09 heavenkiller2018

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

dlinning-jockey avatar Sep 11 '20 15:09 dlinning-jockey

Still not working.

Arnique avatar Oct 06 '20 12:10 Arnique

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.

ghost avatar Oct 06 '20 20:10 ghost

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!

gabrielgianesini avatar Jan 12 '22 20:01 gabrielgianesini

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 :)

47vigen avatar Feb 18 '22 17:02 47vigen

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';

the-nippy avatar Jul 21 '22 07:07 the-nippy

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

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

sofyanemakerri avatar Aug 18 '22 10:08 sofyanemakerri

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.

csckhw303 avatar Jan 29 '23 19:01 csckhw303

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

talaljavedd avatar Feb 08 '23 07:02 talaljavedd

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

sigespweb22 avatar Nov 09 '23 14:11 sigespweb22