Create an account

Very important

  • To access the important data of the forums, you must be active in each forum and especially in the leaks and database leaks section, send data and after sending the data and activity, data and important content will be opened and visible for you.
  • You will only see chat messages from people who are at or below your level.
  • More than 500,000 database leaks and millions of account leaks are waiting for you, so access and view with more activity.
  • Many important data are inactive and inaccessible for you, so open them with activity. (This will be done automatically)


Thread Rating:
  • 308 Vote(s) - 3.53 Average
  • 1
  • 2
  • 3
  • 4
  • 5
npm "failed to parse json"

#1
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
Reply

#2
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"
}
}
Reply

#3

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`
Reply

#4
In Laravel project:

1. Delete 'node_modules' folder;
2. npm cache clean
3. npm update
Reply

#5
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.
Reply

#6
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`
Reply

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

-----------------------------
Reply

#8
Thanks to [Jivings][1] from [this comment][2]:

npm cache clean

solved the problem.

[1]:

[To see links please register here]

[2]:

[To see links please register here]

Reply

#9
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.
Reply

#10
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:

1. Looking for an error File : in npm-debug.log using grep
2. Using sed to generate the fix commands 3-5 only if there are errors
3. Removing the empty file *rm -f* /1 = file path from the first group in regular expression *.\*error File: (.\*)*
4. Cleaning npm cache *npm cache clean*
5. Reinstalling npm *npm install*
6. Running ./npm_reinstall.sh recursively till no errors are found

More information about npm install can be found at [npm-install command documentation][1]


[1]:

[To see links please register here]

Reply



Forum Jump:


Users browsing this thread:
1 Guest(s)

©0Day  2016 - 2023 | All Rights Reserved.  Made with    for the community. Connected through