【问题标题】:npm install error - invalid package.jsonnpm 安装错误 - 无效的 package.json
【发布时间】:2013-09-15 14:58:45
【问题描述】:

我正在使用this 教程来了解在 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 有什么问题吗?

【问题讨论】:

    标签: json node.js express oauth-2.0 npm


    【解决方案1】:

    错误的意思正是它所说的,package.json 中的 JSON 无效,无法正确解析。将"debug" "~0.7.2" 更改为"debug": "~0.7.2"

    【讨论】:

    • 此外,如果您使用 --save npm 标志安装依赖项,则不必手动编辑 package.json
    • 这里有类似的问题。就我而言,我在依赖项末尾缺少逗号: "requirejs": "*", (
    • 在我的情况下没有任何问题,我检查了 jsonlint.com。可能是什么情况。
    【解决方案2】:

    C:\Program Files\nodejs>npm cache verify

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

    【讨论】:

      【解决方案3】:

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

      // package.json
      { ...
      }
      

      删除所有 cmets 后,npm 完美地运行了所有内容。我的评论没有必要,所以我很好。但如果您在 xml 中需要 cmets,请参阅 How do I add comments to package.json for npm install?

      【讨论】:

        【解决方案4】:

        由于我对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"
        }
        

        【讨论】:

          【解决方案5】:

          有时您的package.json 中可能有一些奇怪的 unicode 字符。例如,您可能有\u00A0(unicode 不间断空格)而不是某处的空格。它在编辑器中看起来相同,所以要小心。

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

          【讨论】:

            【解决方案6】:

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

            npm 缓存清理

            【讨论】:

            • 请详细说明这对解决 OP 的问题有何作用并提供更多细节?
            【解决方案7】:

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

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

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

            工作正常

            【讨论】:

            • 这和问题有什么关系
            猜你喜欢
            • 2018-12-25
            • 2015-04-18
            • 1970-01-01
            • 2017-02-10
            • 2023-03-30
            • 1970-01-01
            • 2021-09-23
            • 2011-08-24
            • 2016-03-04
            相关资源
            最近更新 更多