好吧,所以我刚刚安装了NodeJS 9.5.0并进行了双重检查,看到npm是最新版本(5.6.0),到目前为止我一直遇到从{运行简单脚本的问题{1}}文件。
这是我在package.json文件下的内容。
package.json
这是我的index.js。值得庆幸的是,Node能够从cli运行它。
{
"name": "hello_world",
"version": "1.0.0",
"description": "lab-4-hello-world-app",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"start": "node index.js"
},
"author": "Java Drinker",
"license": "ISC"
}
下面是我尝试运行带有调试日志的“start”脚本时收到的错误消息。
console.log("Hello Java Drinker!");
2018-02-22T07_49_53_423Z-的debug.log
npm ERR! file C:\test\package.json
npm ERR! code EJSONPARSE
npm ERR! Failed to parse json
npm ERR! Unexpected string in JSON at position 187 while parsing '{
npm ERR! "name": "hello_world",
npm ERR! "version": '
npm ERR! File: C:\test\package.json
npm ERR! Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript.
npm ERR!
npm ERR! Tell the package author to fix their package.json file. JSON.parse
我想补充一点,我可以运行0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli 'C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js',
1 verbose cli 'run',
1 verbose cli 'start' ]
2 info using npm@5.6.0
3 info using node@v9.5.0
4 verbose stack Error: Failed to parse json
4 verbose stack Unexpected string in JSON at position 187 while parsing '{
4 verbose stack "name": "hello_world",
4 verbose stack "version": '
4 verbose stack at parseError (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:436:11)
4 verbose stack at parseJson (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:104:26)
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:51:5
4 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:78:16
4 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:528:3)
5 verbose cwd C:\test
6 verbose Windows_NT 10.0.16299
7 verbose argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "run" "start"
8 verbose node v9.5.0
9 verbose npm v5.6.0
10 error file C:\test\package.json
11 error code EJSONPARSE
12 error Failed to parse json
12 error Unexpected string in JSON at position 187 while parsing '{
12 error "name": "hello_world",
12 error "version": '
13 error File: C:\test\package.json
14 error Failed to parse package.json data.
14 error package.json must be actual JSON, not just JavaScript.
14 error
14 error Tell the package author to fix their package.json file. JSON.parse
15 verbose exit [ 1, true ]
就好......但似乎任何其他命令都只会导致错误。我想我正在安装npm错误..?
答案 0 :(得分:3)
确保 package.json 文件有效。在提供的示例中,您需要在,
脚本(第6行末尾)之后添加缺少的逗号test
:
{
"name": "hello_world",
"version": "1.0.0",
"description": "lab-4-hello-world-app",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node index.js"
},
"author": "Java Drinker",
"license": "ISC"
}