[英]error installing dependencies from package.json
I just downloaded node.js
and I'm trying to install a couple of dependencies from package.json
, and I keep getting the same error. 我刚刚下载了
node.js
并尝试从package.json
安装几个依赖项,但我不断遇到相同的错误。 I tryied the latest version and the LTS, and both gave the same error. 我尝试了最新版本和LTS,并且都给出了相同的错误。
package.json
{
"name": "snake-ch3",
"dependencies": {
"express": "*",
"express-generator": "*"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-browserify": "~3.4.0",
"grunt-contrib-uglify": "~0.8.0",
"grunt-contrib-watch": "~0.6.1"
}
}
and error: 和错误:
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 'install' ]
2 info using npm@2.15.9
3 info using node@v4.6.0
4 verbose readDependencies loading dependencies from C:\Users\Julian\Desktop\node\ch3\package.json
5 error install Couldn't read dependencies
6 verbose stack Error: Failed to parse json
6 verbose stack No data, empty input at 1:1
6 verbose stack
6 verbose stack ^
6 verbose stack at parseError (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:390:11)
6 verbose stack at parseJson (C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:79:23)
6 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\read-package-json\read-json.js:48:5
6 verbose stack at C:\Program Files\nodejs\node_modules\npm\node_modules\graceful-fs\graceful-fs.js:78:16
6 verbose stack at FSReqWrap.readFileAfterClose [as oncomplete] (fs.js:380:3)
7 verbose cwd C:\Users\Julian\Desktop\node\ch3
8 error Windows_NT 10.0.14393
9 error argv "C:\\Program Files\\nodejs\\node.exe" "C:\\Program Files\\nodejs\\node_modules\\npm\\bin\\npm-cli.js" "install"
10 error node v4.6.0
11 error npm v2.15.9
12 error file C:\Users\Julian\Desktop\node\ch3\package.json
13 error code EJSONPARSE
14 error Failed to parse json
14 error No data, empty input at 1:1
14 error
14 error ^
15 error File: C:\Users\Julian\Desktop\node\ch3\package.json
16 error Failed to parse package.json data.
16 error package.json must be actual JSON, not just JavaScript.
16 error
16 error This is not a bug in npm.
16 error Tell the package author to fix their package.json file. JSON.parse
17 verbose exit [ 1, true ]
I validated the json on https://jsonformatter.curiousconcept.com/ and looked for json parsing errors related to "Windows_NT 10.0.14393" and I'm not getting anything. 我在https://jsonformatter.curiousconcept.com/上验证了json,并寻找与“ Windows_NT 10.0.14393”相关的json解析错误,但我什么也没得到。
I reinstalled node a couple of times so it's not node, or a dowloading problem. 我重新安装了几次节点,所以它不是节点,也不是下载问题。 Can anyone tell me if I'm doing anything wrong?
谁能告诉我我做错了什么吗?
EDIT
编辑
I just tryied running npm init
with all of the default values and then editing it so it has the "dependencies"
and "devDependencies"
and it works all of a sudden. 我只是尝试使用所有默认值运行
npm init
,然后对其进行编辑,使其具有"dependencies"
和"devDependencies"
并且突然起作用。 I tryied doing it again the way I did it before, and I got the same error. 我尝试像以前一样再次进行此操作,但遇到了同样的错误。
now it looks like this: 现在看起来像这样:
package.json package.json
{
"name": "snake-game",
"version": "1.0.0",
"description": "a simple snake game",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "Julian Avar",
"dependencies": {
"express": "*",
"express-generator": "*"
},
"devDependencies": {
"grunt": "~0.4.5",
"grunt-browserify": "~3.4.0",
"grunt-contrib-uglify": "~0.8.0",
"grunt-contrib-watch": "~0.6.1"
}
}
I've noticed that files made in many Windows programs will often prepend the text with bytes in a way that will prevent Unix based programs from reading them correctly (esp if the Unix program is expecting a structure like a JSON file). 我注意到,在许多Windows程序中创建的文件通常会在字节前加上字节,从而阻止基于Unix的程序正确读取它们(尤其是Unix程序期望使用JSON文件之类的结构时)。 From @robertklep's comment, I assume it's a Byte Order Mark, but I've never known the name for it before now.
从@robertklep的评论中,我认为它是一个字节顺序标记,但是我之前从未知道过它的名称。
The recommended way to make a package.json
to avoid this kind of thing is to run npm init
from your command line, to both avoid OS wonkiness and also to make sure you have a minimally valid package.json
when all is said and done. 推荐使用
package.json
来避免这种情况的方法是从命令行运行npm init
,既避免操作系统混乱,又要确保在说完所有步骤后都拥有最低限度的有效package.json
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.