11

我正在使用教程来了解在 Node.js 中实现 oauth2。

这是我的 package.json:

{
  "name": "application-name",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "coffee -w server.coffee"
  },  
  "dependencies": {
    "express": "3.3.4",
    "jade": "*",
    "coffee-script": "latest",
    "passport-http": "latest",
    "passport-http-bearer": "latest",
    "passport-oauth2-client-password": "latest",
    "oauth2orize": "latest",
    "debug" "~0.7.2"
  }
}

我收到错误:

npm ERR! install Couldn't read dependencies
npm ERR! Failed to parse json
npm ERR! Unexpected string
npm ERR! File: /Users/jashua/Desktop/auth/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! System Darwin 12.3.0
npm ERR! command "node" "/usr/local/bin/npm" "install"
npm ERR! cwd /Users/jashua/Desktop/auth
npm ERR! node -v v0.10.15
npm ERR! npm -v 1.3.5
npm ERR! file /Users/jashua/Desktop/auth/package.json
npm ERR! code EJSONPARSE
npm ERR! 
npm ERR! Additional logging details can be found in:
npm ERR!     /Users/me/Desktop/auth/npm-debug.log
npm ERR! not ok code 0

有什么想法我的 package.json 有什么问题吗?

4

7 回答 7

11

该错误意味着它所陈述的内容,您的 JSONpackage.json无效并且无法正确解析。更改"debug" "~0.7.2""debug": "~0.7.2"

于 2013-09-11T14:18:46.303 回答
1

C:\Program Files\nodejs>npm cache verify

在 Windows 10 上修复它,使用管理员命令提示符窗口运行它。

于 2019-12-11T05:54:30.787 回答
0

由于相同的 npm 错误,我到达此页面,但原因不同。查看日志文件后,我意识到 npm 不喜欢我在文件顶行的评论。

// package.json
{ ...
}

删除所有评论后,npm 完美地浏览了所有内容。我的评论没有必要,所以我很好。但是,如果您需要在 xml 中添加注释,请参阅如何为 package.json 添加注释以进行 npm 安装?

于 2014-05-14T23:11:36.113 回答
0

由于我对文件所做的更改,我遇到了同样的问题package.json。我刚刚恢复到package.json文件的备份版本。如果其他人需要,我附在下面:

{"name": "OpenShift-Sample-App",
 "version": "1.0.0",
 "description": "OpenShift Sample Application",
 "keywords": [
   "OpenShift",
   "Node.js",
   "application",
   "openshift"
 ],
 "author": {
   "name": "OpenShift",
   "email": "ramr@example.org",
   "url": "http://www.openshift.com/"
 },
 "homepage": "http://www.openshift.com/",
 "repository": {
   "type": "git",
   "url": "https://github.com/openshift/origin-server"
 },
 "engines": {
   "node": ">= 0.6.0",
   "npm": ">= 1.0.0"
 },
 "dependencies": {
   "express": "~3.4.4"
 },
 "devDependencies": {},
 "bundleDependencies": [],
 "private": true,
 "main": "server.js"
}
于 2014-12-10T17:36:35.950 回答
0

有时您的package.json. 例如,您可能有\u00A0(unicode non-breaking space) 而不是某处的空格。它在编辑器中看起来相同,所以要小心。

(从博客复制一小段配置后,我遇到了这样的问题。)

于 2015-04-07T09:17:08.483 回答
0

使用此命令修复 package.json 相关问题。

npm 缓存清理

于 2016-07-15T14:26:31.497 回答
0

我的项目在 D:\wwwroot\Projetos 2017\Android\PluginTest\PluginTest\plugins\cordova-plugin-iservice

问题是 Projetos(here)2017 之间的空间

我删除了空间:D:\wwwroot\Projetos2017\Android\PluginTest\PluginTest\plugins\cordova-plugin-iservice

和工作正常

于 2017-03-24T04:37:53.303 回答