运行npm run json:server时出现此错误。
npm ERR!缺少脚本:json:
当我打开日志文件时,这就是它所说的:
0信息,如果它以ok结束它是否有效 1 verbose cli ['C:\ Program Files \ nodejs \ node.exe', 1 verbose cli'C:\ Users \ IanP \ AppData \ Roaming \ npm \ node_modules \ npm \ bin \ npm-cli.js', 1 verbose cli'run', 1 verbose cli'json:', 1详细的cli'服务器'] 2信息使用npm@5.5.1 3 info使用node@v8.2.1 4详细堆栈错误:缺少脚本:json: 运行时4个详细堆栈(C:\ Users \ IanP \ AppData \ Roaming \ npm \ node_modules \ npm \ lib \ run-script.js:151:19) 4个详细堆栈位于C:\ Users \ IanP \ AppData \ Roaming \ npm \ node_modules \ npm \ lib \ run-script.js:61:5 4个详细堆栈位于C:\ Users \ IanP \ AppData \ Roaming \ npm \ node_modules \ npm \ node_modules \ read-package-json \ read-json.js:115:5 4个详细堆栈位于C:\ Users \ IanP \ AppData \ Roaming \ npm \ node_modules \ npm \ node_modules \ read-package-json \ read-json.js:402:5 checkBinReferences_上的4个详细堆栈(C:\ Users \ IanP \ AppData \ Roaming \ npm \ node_modules \ npm \ node_modules \ read-package-json \ read-json.js:357:45) 最后4个详细堆栈(C:\ Users \ IanP \ AppData \ Roaming \ npm \ node_modules \ npm \ node_modules \ read-package-json \ read-json.js:400:3) 然后是4个详细堆栈(C:\ Users \ IanP \ AppData \ Roaming \ npm \ node_modules \ npm \ node_modules \ read-package-json \ read-json.js:160:5) 4个详细堆栈位于C:\ Users \ IanP \ AppData \ Roaming \ npm \ node_modules \ npm \ node_modules \ read-package-json \ read-json.js:348:12 4个详细堆栈位于C:\ Users \ IanP \ AppData \ Roaming \ npm \ node_modules \ npm \ node_modules \ graceful-fs \ graceful-fs.js:78:16 tryToString上的4个详细堆栈(fs.js:513:3) 5详细cwd C:\ Users \ IanP \ Documents \ GitHub \ JSONSERVER 6详细的Windows_NT 10.0.15063 7 verbose argv“C:\ Program Files \ nodejs \ node.exe”“C:\ Users \ IanP \ AppData \ Roaming \ npm \ node_modules \ npm \ bin \ npm-cli.js”“run”“json:”“服务器” 8详细节点v8.2.1 9详细npm v5.5.1 缺少10个错误的脚本:json: 11详细退出[1,true]
我的package.json有以下
{
"name": "jsonserver",
"version": "1.0.0",
"description": "Fake REST API for testing",
"main": "index.js",
"scripts": {
"json:server": "json-server --watch db.json"
},
"author": "",
"license": "ISC",
"dependencies": {
"json-server": "^0.12.1"
}
}
我没有修改任何东西,因为它是上次成功运行的。当我第二天开始工作时,突然出现错误。
TIA。
答案 0 :(得分:0)
Rename the "json:server" in scripts to any of the JSON verified characters.
:
are generally used to separate key-value pair.
Even in the log it's pointing out to the same (see verbose line 7).
7 verbose argv "C:\Program Files\nodejs\node.exe" "C:\Users\IanP\AppData\Roaming\npm\node_modules\npm\bin\npm-cli.js" "run" "json:" "server"
So, it would be good idea to replace "json:server" with "json-server" or using camel-Case insted like "jsonServer".
Hope this helps.