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

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

FIXED: Error "Script not found" when running pm2 start npm -- start

NextJS Nov 21, 2022

Error:

When attempting to launch a Next.JS based site using PM2 via a npm script, the following error is returned.

PS C:\Users\AnuragDeep\OneDrive\Desktop\festival\day> pm2 start npm --name AnuragDeep -- run start
[PM2] Spawning PM2 daemon with pm2_home=C:\Users\AnuragDeep\.pm2
[PM2] PM2 Successfully daemonized
[PM2] Starting C:\PROGRAM FILES\NODEJS\NPM.CMD in fork_mode (1 instance)
[PM2] Done.
[PM2][ERROR] Script not found: 

Platform:

Windows OS: 10 and 11

Solution:

Create a deploy.json file in root directory of the next.js app and add following code to the file.

{
    "apps": [
        {
            "name": "AnuragDeep",
            "script": "./node_modules/next/dist/bin/next",
            "env": {
                "PORT": "3000"
            }
        }
    ]
}

Save it, now run following command to start the app via pm2.

pm2 start deploy.json

Visit http://127.0.0.1:3000 in your browser, process has been started successfully. Thanks!



Tags

Anurag Deep

Logical by Mind, Creative by Heart