Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pm2 can't start script with :

Tags:

node.js

pm2

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"
like image 305
Mj Ebrahimzadeh Avatar asked Apr 20 '26 12:04

Mj Ebrahimzadeh


1 Answers

You can use following way to run the script :

pm2 start npm --name "your-app-name" -- run "start:dev"
like image 146
undefined Avatar answered Apr 22 '26 02:04

undefined



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!