简体   繁体   中英

Npm ERR code EJSONPARSE - Failed to parse json

So I was just about to setup this login form for my page using node.js I ran

npm init

and went trough the various steps to complete it. When I was all done with that, and the package.json file had been created I added these lines of code"

 dependencies": {
         "bcryptjs": "*",
         "body-parser": "*",
         "connect-flash": "*",
         "cookie-parser": "^1.4.1",
         "express": "*",
         "express-handlebars": "*",
         "express-messages": "*",
         "express-session": "*",
         "express-validator": "*",
         "mongodb": "*",
         "mongoose": "*",
         "passport": "*",
         "passport-http": "*",
         "passport-local": "*"   }

I now ran the command

npm install

But ended up getting these ERRORS

npm ERR! file /Users/albingroen/Desktop/newProject/package.json
npm ERR! code EJSONPARSE
npm ERR! Failed to parse json
npm ERR! Unexpected token '\n' at 26:5
npm ERR!   }
npm ERR!     ^
npm ERR! File: /Users/albingroen/Desktop/newProject/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

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/albingroen/.npm/_logs/2017-04-04T18_52_34_920Z-debug.log

I have tried following things:

  • Cleaning the node cache

  • Using different terminal

  • Updating node.js

  • Updating mongodb

  • Changing location of package.json

  • Running npm install without the added dependencies

  • Deleting the nodemodules mapp

I really don't know what to do anymore. Somebody got an idea?

I had the same error. It is caused by wrong syntax within your package.json. I solved it by removing an unnecessary ',' at the end of my last dependency, but it can be different for everyone. Looking over the package.json syntax would be the best bet.

Like the above answer, i checked my files for any unnecessary ',' but everything looked good.

I tried this in terminal, and it worked.

npm run start

and then, install your dependencies, for me i did it as

npm install express mongoose

您一定在 package.json 文件中遗漏了一些“}”或其他内容,只需检查它或将其与旧版本的文件进行比较,它对我有很多帮助

I have the same error because I forget to give a comma "," in my JSON file. After putting comma in JSON file it worked fine.

Check Whether You have created the package.json file. If not create it and initialize it with {}.

在我的反应项目中,在 package.json 中,我的项目名称在一封信中给出。当我将其更改为一个单词时,小写命令适用于 e 然后。

Just delete the unnecessary commas, that is, at the end of each object in your package.json.

My path: SolutionName/ClientApp/src/package.json In my case it was in "lodash".

"resolutions": {
 "url-parse": "> = 1.5.0",
 "lodash": "> = 4.17.21", <-- I deleted this comma!

}

Check your package.json and add

"web-vitals": "^3.1.0" 

to your dependencies.

That has worked for me.

i faced the same error. I solved removing the extra commas

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM