julian avar julian avar - 3 months ago 67
JSON Question

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. I tryied the latest version and the LTS, and both gave the same error.

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.

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. I tryied doing it again the way I did it before, and I got the same error.

now it looks like this:

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"
}
}

Answer

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). From @robertklep's comment, I assume it's a Byte Order Mark, but I've never known the name for it before now.

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.