30

I used http://jsonlint.com/ to check the syntax for this package.json file

{
  "name": "hello-world",
  "description": "hello world test app",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "express": “4.6.1"
  }
}

it returns the error

Parse error on line 7:
...        "express": “4.6.1"  }}
----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['

not sure what is wrong with this. terminal is throwing the error for using npm install

"Failed to parse package.json data.
npm ERR! package.json must be actual JSON, not just JavaScript."
Korem
  • 11,383
  • 7
  • 55
  • 72
nmolloy93
  • 401
  • 1
  • 4
  • 3
  • Note: If you are try running the npm build using azure devops pipeline, make sure on git checkout the files are not under git lfs. If the `json` files are in git lfs, then follow [this guide](https://stackoverflow.com/a/56838104/1176573). – Rajesh Swarnkar Feb 21 '22 at 07:43
  • `“` is not the same character as `"` – Caleth May 30 '23 at 12:28

10 Answers10

36

Just type npm cache clean on prompt and all the things must to work again.

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
  • 3
    It appears that some of us are getting this error without any 'curly' quotes. In this case, this answer works a treat... I like the fact that NPM declares 'This is not a bug in NPM' Lol. Clearly a bug in npm. – Tom Nov 23 '15 at 10:39
  • Thanks, this helped a lot. :) – inquisitive Feb 01 '16 at 05:54
  • 1
    As of npm@5, the npm cache self-heals from corruption issues and data extracted from the cache is guaranteed to be valid. If you want to make sure everything is consistent, use `npm cache verify` instead – DJ2 Jun 07 '18 at 20:42
  • 1
    update as it is relevant on the newer version but wasnt at the time of the above posting. As of npm@5 you have to do a ```npm cache clean --force``` – CRTLBREAK Sep 09 '20 at 22:16
26

package.json file should not be empty.

If you have empty package json file just add {}.

and try again.

enter image description here

Lijo
  • 6,498
  • 5
  • 49
  • 60
22

You have curly quotes before the 4 - “4.6.1". Change that to a regular quote character and it'll pass.

glortho
  • 13,120
  • 8
  • 49
  • 45
7

It's a general syntax error message. Received the same error when a comma was missing in my code. Just running npm cache clean won't work if there's a glitch in the code. I added the missing comma and the program ran to success.

Yusuf
  • 2,459
  • 1
  • 12
  • 5
1

I had got this same type of error. The answer, npm cache clean once solved my question but I got stuck for another reason while installing express.js

  1. There is a short suggestion that I learned from this segment is to put just {} in the package.json file. I didn't try that but I believe that would work.

  2. I have did another work.

I typed npm init and then put some description on this file like project name, author, version etc. Then I have terminated. And that made my file the real JSON Format. And I had my problem solved.

1

Go on google and search for a json code online editor and copy that your package.json code and paste it there, the json editor should flag any syntax errors. I got the same error and for me it was just syntax and that worked for me.

Try this json code editor: https://jsoneditoronline.org/#left=local.nuxuti

Ndalama
  • 11
  • 1
0

You are using wrong quotation marks in line 7.

This version will do the job. ;-)

{
  "name": "hello-world",
  "description": "hello world test app",
  "version": "0.0.1",
  "private": true,
  "dependencies": {
    "express": "4.6.1"
  }
}
chrischma
  • 101
  • 1
  • 4
  • Hi, thanks for your contribution. The answer you posted on a 6 yr old question, is similar to the other existing answers . Better to look for new questions to answer and contribute to the community. – Ank May 25 '21 at 06:44
0

Just type npm cache clean on prompt and all the things must to work again.

other option is to check if you did not comment any thing in your JSON code, because JSON does not support comments.

Amoo Faruk
  • 63
  • 5
  • npm cache clean does not work, npm ERR! If you're sure you want to delete the entire cache, rerun this command npm ERR! with --force. – jahan8409 Apr 13 '22 at 18:06
0

I faced the same problem, and I found out that in package.json I added a trailing comma in an object ("scripts" in my case). By removing it, problem solved!

0

I was also facing the same issue, I would suggest looking into the code once because generally, it's due to some syntax error.

Isha Shaw
  • 64
  • 1
  • 7