Javascript 这个 package.json 文件需要改变什么才能使用 npm 0.3.0?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5644410/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-23 18:14:20  来源:igfitidea点击:

What needs to change in this package.json file to work with npm 0.3.0?

javascriptjsonnode.jspackagenpm

提问by fancy

Trying to use a lib but getting this error...

尝试使用 lib 但收到此错误...

npm ERR! JSON.parse Failed to parse package.json data.
npm ERR! JSON.parse Note that package.json must be actual JSON, not
npm ERR! JSON.parse just a JavaScript object.
npm ERR! JSON.parse 
npm ERR! JSON.parse This changed in npm 0.3.0, and is not a bug in npm.
npm ERR! JSON.parse Tell the package author to fix their package.json file.

Not sure what changes are likely needed to make it valid JSON, thanks very much!

不确定可能需要进行哪些更改才能使其成为有效的 JSON,非常感谢!

回答by Afshin Mehrabani

Just to complete the answer, you can simply use an online JSON validator to validate your package.json.
I highly recommend http://jsonlint.com/, paste your package.jsonin the textarea and click on the Validate button, that's all!

为了完成答案,您只需使用在线 JSON 验证器来验证您的package.json.
我强烈推荐http://jsonlint.com/,将您package.json的内容粘贴到 textarea 中,然后单击“验证”按钮,仅此而已!

回答by Jon Gauthier

Valid JSON must have both keys and values of an object in quotes. Surround all of your keys in quotation marks and that should make the error go away.

有效的 JSON 必须在引号中包含对象的键和值。用引号将所有键括起来,这应该会使错误消失。

Reference: JSON spec

参考:JSON 规范

Update: I did the dirty work for you. Let me know if this fixes it.

更新:我为你做了肮脏的工作。如果这能解决问题,请告诉我。

{ "name": "embedly"
, "version": "0.3.2"
, "description": "Embedly client library for node"
, "homepage": "https://github.com/embedly/embedly-node"
, "keywords": []
, "author":
  { "name": "Bob Corsaro"
  , "email": "[email protected]"
  , "url": "http://www.google.com/profiles/rcorsaro"
  }
, "repository":
  { "type": "git"
  , "url": "git://github.com/embedly/embedly-node"
  }
, "bugs": { "web": "http://github.com/embedly/embedly-node/issues/" }
, "directories":
  { "doc": "./docs"
  , "lib": "./lib"
  , "test": "./test"
  }
, "dependencies": {"hashish": "", "qs": ""}
, "devDependencies": {"vows": ">= 0.5.6"}
, "main": "./lib/embedly.js"
, "scripts": { "test": "vows" }
, "bin":
  { "embedly_oembed": "bin/embedly_oembed.js"
  , "embedly_objectify": "bin/embedly_objectify.js"
  , "embedly_preview": "bin/embedly_preview.js"
  }
}

回答by Barun

Super cool way to fix / validate the package.json :

修复/验证 package.json 的超酷方法:

node package.json

node package.json

and you have your json validated or the error line.

并且您已验证 json 或错误行。

Why use jsonlint, sounds pretty lame.

为什么使用jsonlint,听起来很蹩脚。

回答by Pero P.

In addition to @Hans Engel's answer use npm help jsonto get the specification of what should be in the package.json file

除了@Hans Engel 的回答用于npm help json获取 package.json 文件中应该包含的内容的规范之外

回答by dev_khan

I have been through this problem and in my case it was just that in place of comma(,). I have used dot(.). You can simply open it up in any JSON validator and it will help you up. One of the JSON validator's link is as follows . http://www.bodurov.com/JsonFormatter/

我已经解决了这个问题,就我而言,它只是代替逗号(,)。我用过点(.)。你可以简单地在任何 JSON 验证器中打开它,它会帮助你。JSON 验证器的链接之一如下。 http://www.bodurov.com/JsonFormatter/

回答by Avijit Majhi

I also got the same error message, first run npm package.jsonto check errors in package.json file, if not then run npm cache clean.

我也收到了同样的错误消息,首先运行npm package.json以检查 package.json 文件中的错误,如果没有则运行npm cache clean