我有一个我需要研究的nodejs应用程序,但不幸的是它无法启动。该员工离开公司并没有在应用程序上留下太多信息,所以我在这里迷失了。
该应用以pm2运行。当我执行“pm2 start ecosystem.json”时,状态为“在线”几秒钟,然后更改为“错误”。
在“pm2 desc ID”的日志文件中出现以下错误。
SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Object.<anonymous> (/usr/lib/node_modules/pm2/lib/ProcessContainerFork.js:83:21)
at Module._compile (module.js:635:30)
at Object.Module._extensions..js (module.js:646:10)
这是package.json
{
"name": "njs-data-api",
"version": "0.0.0",
"private": true,
"scripts": {
"watch": "NODE_ENV=development nodemon --exec babel-node -- ./bin/www",
"build": "rm -rf dist && babel src --ignore __tests__ --out-dir dist",
"sync": "copy the built files to staging",
"deploy": "npm run build && npm run sync",
"start": "NODE_ENV=staging node ./bin/www"
},
"dependencies": {
"bluebird": "^3.5.1",
"body-parser": "~1.18.2",
"bunyan": "^1.8.12",
"cookie-parser": "~1.4.3",
"debug": "~2.6.9",
"dotenv": "^4.0.0",
"express": "~4.15.5",
"joi": "^13.2.0",
"moment": "^2.22.1",
"morgan": "~1.9.0",
"pg": "^7.4.1",
"pg-promise": "^7.5.4",
"pg-pubsub": "^0.3.0",
"pm2": "^2.10.2",
"pug": "2.0.0-beta11",
"redis": "^2.8.0",
"serve-favicon": "~2.4.5"
},
"devDependencies": {
"babel-cli": "^6.26.0",
"babel-preset-es2015-node6": "^0.4.0",
"babel-preset-stage-0": "^6.24.1",
"colors": "^1.2.1",
"nodemon": "^1.17.3"
}
}
任何有关如何解决此错误的帮助都将受到高度赞赏!
修改
这是 ecosystem.json
的内容{
"apps": [
{
"name": "User Data Api",
"script": "./bin/www",
"watch": true,
"merge_logs": true,
"min_uptime": 4000,
"max_restarts": 50,
"log_date_format": "YYYY-MM-DD HH:mm:ss.SSS",
"env": {
}
}
]
}
当我运行节点./bin/www 时,我收到以下错误:
的/ mnt / C / ubuntu的/的NodeJS / NJS-用户数据API / bin中/ WWW:89 }
SyntaxError: Invalid or unexpected token
at createScript (vm.js:80:10)
at Object.runInThisContext (vm.js:139:10)
at Module._compile (module.js:599:28)
at Object.Module._extensions..js (module.js:646:10)
at Module.load (module.js:554:32)
at tryModuleLoad (module.js:497:12)
at Function.Module._load (module.js:489:3)
at Function.Module.runMain (module.js:676:10)
at startup (bootstrap_node.js:187:16)
at bootstrap_node.js:608:3
第89行是最后一个js函数的结束大括号
答案 0 :(得分:0)
不确定问题的根源,但我修复了它。
当我运行node ./bin/www时,我收到以下错误:
/ mnt / c / ubuntu / nodejs / njs-user-data-api / bin / www:89}
这是文件末尾非常简单的函数的结束大括号。我注意到当我尝试将PHPStorm的标记/光标移动到右括号时,它是不可能的,并且IDE无法检测到开括号。所以我打了退格区5-6次,直到大括号被删除。当我再次输入大括号时,IDE能够检测到开括号和闭合大括号,一切正常。
任何人都知道可能导致此问题的原因是什么?