Reputation: 1030
When I'm trying to install express with npm I always get the following error:
Failed to parse json
No data, empty input at 1:1
File: /root/.npm/inherits/2.0.1/package/package.json
Failed to parse package.json data.
package.json must be actual JSON, not just JavaScript.
This is not a bug in npm.
Tell the package author to fix their package.json file. JSON.parse
What am I doing wrong?
sudo npm install -g express
OS is Ubuntu 12.04 (precise) armhf
Upvotes: 46
Views: 114367
Reputation: 572
For me the issue was fixed by changing the name of the package from
"name": "portfolio"
to
"name": "portfolio2"
Upvotes: 1
Reputation: 13
1.Basically it comes for wrong placement of comma so remove comma at wrong position(esp error occurs for placing comma(,) before closing flower brace('}') in package.json so look into it. This is one solution
sudo npm cache clean
sudo chown -R 1000:1000 "...path/.npm"
Upvotes: 0
Reputation: 385
remove any unnecessary comments, the error you referred occurs usually due to the syntax error. Or if this won't help, try to clean the cache by "npm cache clean".
Upvotes: 0
Reputation: 53
For those of you who are new to this like me, I forgot to initialize my JSON package with the npm init command.
Upvotes: 0
Reputation: 179
I solved the issue using below steps:
Delete node_modules
folder
Delete package-lock.json
file
Run npm install
Run npm start
Upvotes: 4
Reputation: 8063
I think you may be did some change in package.json and that is not valid
npm init
npm install express
Upvotes: 0
Reputation: 57
Please check with unused white spaces inside package.json file, it might cause by extra white spaces.
Upvotes: 0
Reputation: 177
I faced this problem several times before I got used to using NPM. Most off the time it was because I failed to use npm init before npm install
Upvotes: 1
Reputation: 309
In addition to Pank's answer, if you encounter this kind of error
npm ERR! code EJSONPARSE
npm ERR! JSON.parse Failed to parse json
npm ERR! JSON.parse Unexpected token } in JSON at position 550 while parsing near '...eact": "^7.12.4",
npm ERR! JSON.parse },
npm ERR! JSON.parse "dependencies":...'
npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse package.json must be actual JSON, not just JavaScript.
You need to make sure your package.json
is a valid json, not a javascript.
Upvotes: 0
Reputation: 1818
In my case
Missing a comma somewhere in a package.json
Check your package.json file.
After that sudo npm install
or
To clean the cache memory.
sudo npm cache clean
Upvotes: 0
Reputation: 441
The following bash script fixes the problem automatically
#!/usr/bin/env bash
echo -e '#!/usr/bin/env bash' > npm_install.sh
cat npm-debug.log | grep 'error File:' | sed -n 's:.*error File\: \(.*\):echo "Removing \1"\nrm -f \1\necho "Cleaning npm cache"\nnpm cache clean\necho "Reinstalling npm"\nnpm install\n./npm_reinstall.sh:p' >> npm_install.sh
chmod +x npm_install.sh
./npm_install.sh
It should be saved to npm_reinstall.sh and granted execution permissions using
chmod +x npm_reinstall.sh
The script is preforming the following tasks:
More information about npm install can be found at npm-install command documentation
Upvotes: 0
Reputation: 221
I experienced a similar issue today after updating Node on Windows 10. My local build tasks started failing and upon investigation I saw all these errors in my dependency package.json files. None of them were valid JSON anymore and I was seeing messages like:
npm WARN Failed to parse json
npm WARN Unexpected token '\u0019' at 1:1
npm WARN ������2�����bE�;���1L �\5�e���k2?��,?;��쏏a��(T��w��+I��/�6�P} ��i�|e�
npm WARN ^
in my console.
This story has a happy ending as it turns out that new Node doesn't play nice with old NPM and updating NPM to version 5 solved the problem. Hope this helps other folks who may experience this variation on this issue.
Upvotes: 0
Reputation: 1030
Thanks to Jivings from this comment:
npm cache clean
solved the problem.
Upvotes: 103
Reputation: 93
Mostly, this error is due to a syntax error in package.json file. In my case, the opening curly brace for dependencies object in package.json was missing:-
Code--------------------------------
{
"name": "psrxjs",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",
"dependencies":
"rxjs": "^5.4.3"
}
}
Upvotes: 5
Reputation: 372
I had the same problem but "npm cache clean" didnt resolve it for me. I had to go back to my package.json and realize i had comma where it shouldn't i suppose as shown below:
},
"devDependencies": {
"axios": "^0.15.3",
"bootstrap-sass": "^3.3.7",
"cross-env": "^3.2.4",
"jquery": "^3.1.1",
"laravel-mix": "0.*",
"lodash": "^4.17.4",
"vue": "^2.1.10",
}
after the "vue..." so I deleted that and every went back to normal. So it is worth checking the package.json file first before running npm cache clean
Upvotes: 14
Reputation: 1
Try to open your txt editor and select "plain text" for the package.json then re-save. Sometimes issue is overlooked and simple things are holding the answer.
Upvotes: -1
Reputation: 49
In Laravel project:
Upvotes: 4
Reputation: 518
I also got the same error message while run npm install
, first run npm package.json
to check errors in package.json file, if not then run npm cache clean
Upvotes: 2
Reputation: 11
Don't forget to edit your package.json, escpeially the dependencies.
For example, one of my chatting room projects needs the following content in package.json:
{
"name":"chatrooms",
"version":"0.0.1",
"description":"Minimalist multi-room chat server",
"dependencies":{
"socket.io":"~0.9.6",
"mime":"~1.2.7"
}
}
Upvotes: -1