18

This is probably a Windows specific issue but I haven't found any information when googling this issue. I had been using ionic framework which relies on Cordova (or Phonegap). However, the problem is not specific to any of these packages. I see this error quite often. So, the error is when I run a command such as the following:

npm install -g cordova

However, I could substitute various other packages and get the same error. I'll paste the snippet (very brief) below of the error message. What is strange is that I had an ionic project working in that directory earlier. Then today it told me that ionic could not be found. My hunch is that this is a different issue than the main issue I am describing here.

I installed git bash so I do have a linux-like environment that I could try. I would just select Git Bash for a bash window with various bash commands. If there is an easier way to fix this for Windows users, please let me know. I have seen courses on Pluralsight where the instructors seem to be happily using npm with no problems. Also, when I use yeoman, I also at some point, in many cases, get the same error.
The error is

npm ERR! Failed to parse json
npm Unexpected token '\u0000' at 1:1
npm ERR!
npm ERR! ^
npm ERR! File: c:\Users\Bruce\AppData\Roaming\npm-cache\amdefine\1.0.0\package\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! This is not a bug in npm
npm ERR! Tell the package author to fix their package.json file. JSON.parse.

Thanks in advance for any help/advice, Bruce

1 Answer 1

51

Via this question on SO it could be that you just have to do:

npm cache clean.

But, also try the other methods suggested there like adding the registry option:

npm install <packagename> --registry http://registry.npmjs.org/.

Or, if you've been mingling with the package.json file by yourself, check if it's valid.

3
  • I apologize for not commenting sooner. I had been in chat and got the same answer you suggested first, of cleaning the cache. I'll have to check the other related question and the --registry flag, as I don't know that off the top of my head. But, no, I haven't mingled with the package.json files, these were fresh installs of packages available on npmjs.org... though, I did try to update them, using the install command instead of update. Commented Jul 28, 2015 at 12:46
  • No problem, so basically the cache cleaning helped in the end, or the reinstall?
    – Nikola
    Commented Jul 28, 2015 at 13:12
  • 3
    FWIW, the cache cleaning was all I needed.
    – slushy
    Commented Aug 2, 2016 at 16:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.