Mj Ebrahimzadeh
Mj Ebrahimzadeh

Reputation: 647

pm2 can't start script with :

I want to start my script with pm2 in Windows, but I get the error: SyntaxError: Unexpected token ':'

my start script is start:dev and to run that I say: pm2 start npm -- 'start:dev'

my script:

"scripts": {
    "start": "NODE_ENV=production node dist/src/index.js",
    "build": "tsc -p . && ncp productionenv ./dist/src/.env",
    "start:dev": "npm run build:dev",
    "build:dev": "nodemon src/index.ts --exec ts-node src/index.ts -e ts,graphql",
    "test": "jest"
  },

Full err:

App [gateway:0] exited with code [1] via signal [SIGINT]
PM2        | App [gateway:0] starting in -fork mode-
PM2        | App [gateway:0] online
0|gateway  | C:\PROGRAM FILES\NODEJS\NPM.CMD:1
0|gateway  | :: Created by npm, please don't edit manually.
0|gateway  | ^
0|gateway  | SyntaxError: Unexpected token ':'
0|gateway  |     at Object.compileFunction (node:vm:352:18)
0|gateway  |     at wrapSafe (node:internal/modules/cjs/loader:1031:15)
0|gateway  |     at Module._compile (node:internal/modules/cjs/loader:1065:27)
0|gateway  |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
0|gateway  |     at Module.load (node:internal/modules/cjs/loader:981:32)
0|gateway  |     at Function.Module._load (node:internal/modules/cjs/loader:822:12)
0|gateway  |     at Object.<anonymous> (C:\Users\xx\AppData\Roaming\npm\node_modules\pm2\lib\ProcessContainerFork.js:33:23)
0|gateway  |     at Module._compile (node:internal/modules/cjs/loader:1101:14)
0|gateway  |     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
0|gateway  |     at Module.load (node:internal/modules/cjs/loader:981:32)
PM2        | App [gateway:0] exited with code [1] via signal [SIGINT]
PM2        | Script C:\PROGRAM FILES\NODEJS\NPM.CMD had too many unstable restarts (16). Stopped. "errored"

Upvotes: 2

Views: 17216

Answers (3)

Tan Nguyen
Tan Nguyen

Reputation: 1103

Only for who run NextJs.

should create deploy.json file:

{
    "apps": [
        {
            "name": "dicom-interactive",
            "script": "./node_modules/next/dist/bin/next",
            "args": "start",
            "env": {
                "PORT": "3000",
            }
        }
    ]
}

run

pm2 start deploy.json

Upvotes: 4

undefined
undefined

Reputation: 86

You can use following way to run the script :

pm2 start npm --name "your-app-name" -- run "start:dev"

Upvotes: 5

Apoorva Chikara
Apoorva Chikara

Reputation: 8773

You are actually running the custom script, so it needs to be run in a different way:

pm2 start npm run start:dev

Whenever you add any custom script npm run scriptname is the command to follow. If you want to know more about it, check here.

Also, it should be a part of the script:

"scripts": {
    "start": "NODE_ENV=development npm start",
    "start:dev": "npm start --watch",
    "start:debug": "npm start --debug --watch",
    "start:prod": "node dist/main",
  },

Upvotes: 3

Related Questions