pm2 无法启动脚本:
pm2 can't start script with :
我想在 Windows 中使用 pm2 启动我的脚本,但我收到错误:
SyntaxError: Unexpected token ':'
我的开始脚本是 start:dev
到 运行 我说:pm2 start npm -- 'start:dev'
我的脚本:
"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"
},
完全错误:
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"
您实际上是在 运行 自定义脚本,因此它需要 运行 以不同的方式:
pm2 start npm run start:dev
无论何时添加任何自定义脚本,npm run scriptname
都是要遵循的命令。如果您想了解更多信息,请查看 here.
此外,它应该是脚本的一部分:
"scripts": {
"start": "NODE_ENV=development npm start",
"start:dev": "npm start --watch",
"start:debug": "npm start --debug --watch",
"start:prod": "node dist/main",
},
您可以使用以下方式来 运行 脚本 :
pm2 start npm --name "your-app-name" -- run "start:dev"
我想在 Windows 中使用 pm2 启动我的脚本,但我收到错误:
SyntaxError: Unexpected token ':'
我的开始脚本是 start:dev
到 运行 我说:pm2 start npm -- 'start:dev'
我的脚本:
"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"
},
完全错误:
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"
您实际上是在 运行 自定义脚本,因此它需要 运行 以不同的方式:
pm2 start npm run start:dev
无论何时添加任何自定义脚本,npm run scriptname
都是要遵循的命令。如果您想了解更多信息,请查看 here.
此外,它应该是脚本的一部分:
"scripts": {
"start": "NODE_ENV=development npm start",
"start:dev": "npm start --watch",
"start:debug": "npm start --debug --watch",
"start:prod": "node dist/main",
},
您可以使用以下方式来 运行 脚本 :
pm2 start npm --name "your-app-name" -- run "start:dev"