简体   繁体   English

Npm ERR 代码 EJSONPARSE - 无法解析 json

[英]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所以我正要使用 node.js 为我的页面设置这个登录表单我跑了

npm init npm 初始化

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"当我完成所有这些并创建了 package.json 文件时,我添加了这些代码行”

 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 npm 安装

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更新 node.js

  • Updating mongodb更新中 mongodb

  • Changing location of package.json更改 package.json 的位置

  • Running npm install without the added dependencies在没有添加依赖项的情况下运行 npm 安装

  • 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.它是由 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.查看 package.json 语法将是最好的选择。

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.我有同样的错误,因为我忘记在我的 JSON 文件中给出一个逗号“,”。 After putting comma in JSON file it worked fine.将逗号放入 JSON 文件后,它工作正常。

Check Whether You have created the package.json file.检查您是否已创建 package.json 文件。 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.只需删除不必要的逗号,即 package.json 中每个对象的末尾。

My path: SolutionName/ClientApp/src/package.json In my case it was in "lodash".我的路径:SolutionName/ClientApp/src/package.json 就我而言,它在“lodash”中。

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

} }

Check your package.json and add检查你的package.json并添加

"web-vitals": "^3.1.0" 

to your dependencies.对你的依赖。

That has worked for me.这对我有用。

i faced the same error.我遇到了同样的错误。 I solved removing the extra commas我解决了删除多余的逗号

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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