問題描述
當我嘗試使用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
我究竟做錯了什麽?
sudo npm install -g express
操作係統是Ubuntu 12.04(precise)armhf
最佳辦法
npm cache clean
解決了問題。
次佳辦法
我有同樣的問題,但“ 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",
}
在”vue…”之後,我刪除了該文件,一切恢複了正常。因此值得在運行npm cache clean
之前先檢查package.json文件
第三種辦法
在Laravel項目中:
-
刪除’node_modules’文件夾;
-
npm緩存清理
-
npm更新
第四種辦法
通常,此錯誤是由於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"
}
}
第五種辦法
運行npm install
時,我也得到了相同的錯誤消息,先運行npm package.json
來檢查package.json文件中的錯誤,如果沒有,則運行npm cache clean