npm"无法解析json"

kov*_*gel 40 ubuntu node.js npm

当我尝试使用npm安装express时,我总是会收到以下错误:

Failed to parse json
No data, empty input at 1:1
File: /root/.npm/inherits/2.0.1/package/package.json
Failed to parse package.json data.
package.json must be actual JSON, not just JavaScript.

This is not a bug in npm.
Tell the package author to fix their package.json file. JSON.parse
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

 sudo npm install -g express
Run Code Online (Sandbox Code Playgroud)

操作系统是Ubuntu 12.04(精确)armhf

kov*_*gel 99

由于Jivings来自此评论:

npm cache clean
Run Code Online (Sandbox Code Playgroud)

解决了这个问题.

  • 对于npm @ 5,只需添加`npm cache clean --force` (3认同)

小智 8

我遇到了同样的问题,但"npm cache clean"并没有解决它.我不得不回到我的package.json并意识到我有逗号,我想不应该如下所示:

},
  "devDependencies": {
    "axios": "^0.15.3",
    "bootstrap-sass": "^3.3.7",
    "cross-env": "^3.2.4",
    "jquery": "^3.1.1",
    "laravel-mix": "0.*",
    "lodash": "^4.17.4",
    "vue": "^2.1.10",
  }
Run Code Online (Sandbox Code Playgroud)

在"vue ..."之后,我删除了它,每一次都恢复正常.所以在运行之前首先检查package.json文件值得的 npm cache clean


Ash*_*hra 5

大多数情况下,此错误是由于 package.json 文件中的语法错误造成的。就我而言,package.json 中的依赖项对象的左花括号丢失了:-

代码 - - - - - - - - - - - - - - - -

{
  "name": "psrxjs",
  "version": "1.0.0",
  "description": "",
  "main": "index.js",
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "author": "",
  "license": "ISC",
  "dependencies": 
    "rxjs": "^5.4.3"
  }
}
Run Code Online (Sandbox Code Playgroud)