Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
dlinning-jockey opened this issue Aug 14, 2020 · 13 comments
Open

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

dlinning-jockey opened this issue Aug 14, 2020 · 13 comments

Comments

@dlinning-jockey
Copy link

dlinning-jockey commented Aug 14, 2020

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 dlinning-jockey changed the title Error: Script not found: ...\start Error "Script not found" when running pm2 start npm -- start Aug 19, 2020
@nibman
Copy link

nibman commented Sep 10, 2020

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
Copy link

nibman commented Sep 10, 2020

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

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

@heavenkiller2018
Copy link

@dlinning-jockey ,did you fixed it already?

@dlinning-jockey
Copy link
Author

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

@Arnique
Copy link

Arnique commented Oct 6, 2020

Still not working.

@ghost
Copy link

ghost commented Oct 6, 2020

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
Copy link

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
Copy link

47vigen commented Feb 18, 2022

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
Copy link

the-nippy commented Jul 21, 2022

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
Copy link

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

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

@csckhw303
Copy link

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
Copy link

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
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests