【问题标题】:npm ERR! Unexpected end of JSON input while parsing near '...registry.npmjs.org/@i'npm 错误!在“...registry.npmjs.org/@i”附近解析时 JSON 输入意外结束
【发布时间】:2019-10-16 16:04:57
【问题描述】:

我是 ionic 新手,我仍在尝试安装它。每次我写一个像npm install -g ionic cordova 这样的离子命令时,我都会收到这个错误

    npm ERR! Unexpected end of JSON input while parsing near '...de":"0.6.2","express"'

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\DwayneT\AppData\Roaming\npm-cache\_logs\2019-05-31T01_51_23_542Z-debug.log

'

这是我的日志文件

0 info it worked if it ends with ok
1 verbose cli [ 'C:\\Program Files\\nodejs\\node.exe',
1 verbose cli   
'C:\\Users\\DwayneT\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm- 
cli.js',
1 verbose cli   'install',
1 verbose cli   '-g',
1 verbose cli   'ionic',
1 verbose cli   'cordova' ]
2 info using npm@6.9.0
3 info using node@v8.11.1
4 verbose npm-session bf0a16c3729a6897
5 silly install loadCurrentTree
6 silly install readGlobalPackageData
7 http fetch GET 304 http://registry.npmjs.org/cordova 1407ms (from cache)
8 silly fetchPackageMetaData error for cordova@latest Unexpected end of JSON 
input while parsing near '...de":"0.6.2","express"'
9 http fetch GET 304 http://registry.npmjs.org/ionic 1418ms (from cache)
10 silly pacote tag manifest for ionic@latest fetched in 1452ms
11 timing stage:rollbackFailedOptional Completed in 1ms
12 timing stage:runTopLevelLifecycles Completed in 1466ms
13 verbose stack SyntaxError: Unexpected end of JSON input while parsing 
near '...de":"0.6.2","express"'
13 verbose stack     at JSON.parse (<anonymous>)
13 verbose stack     at parseJson 
(C:\Users\DwayneT\AppData\Roaming\npm\node_modules\npm\node_modules\json- 
parse-better-errors\index.js:7:17)
13 verbose stack     at consumeBody.call.then.buffer 
(C:\Users\DwayneT\AppData\Roaming\npm\node_modules\npm\node_modules\node- 
fetch-npm\src\body.js:96:50)
13 verbose stack     at <anonymous>
13 verbose stack     at process._tickCallback 
(internal/process/next_tick.js:188:7)
14 verbose cwd C:\Users\DwayneT
15 verbose Windows_NT 10.0.18362
16 verbose argv "C:\\Program Files\\nodejs\\node.exe" 
"C:\\Users\\DwayneT\\AppData\\Roaming\\npm\\node_modules\\npm\\bin\\npm- 
cli.js" "install" "-g" "ionic" "cordova"
17 verbose node v8.11.1
18 verbose npm  v6.9.0
19 error Unexpected end of JSON input while parsing near 
'...de":"0.6.2","express"'
20 verbose exit [ 1, true ]

我尝试了很多解决方案,包括

npm cache clean --force

但似乎没有任何效果,我现在就是。请协助。我正在使用节点 v 8

【问题讨论】:

  • 你的节点版本是多少。我建议使用 8.*.* 或 10
  • 我使用的是版本 8,尝试了 10 但有同样的问题,所以现在使用 8
  • 对我有用的是 npm install --cache /tmp/empty-cache 在运行 npm cache clean 时从错误 npm show 中得到此信息“截至 npm@5,npm 缓存从损坏问题和从缓存保证有效。如果您想确保一切一致,请改用“npm cache verify”。另一方面,如果您正在调试安装程序的问题,您可以使用npm install --cache /tmp/empty-cache 来使用临时缓存而不是实际缓存。如果您确定要删除整个缓存,请使用 --force" 重新运行此命令

标签: node.js ionic-framework


【解决方案1】:

这是 npm 损坏缓存的问题。您可以使用 npm 本身清除它。

我解决了

npm cache clean --force

然后更新 npm

npm i npm@latest -g

然后正常使用你的 npm install 命令

npm install 

【讨论】:

  • 谢谢你,朋友!您的回答最有帮助!
【解决方案2】:

尝试运行npm cache clean --force 然后重新运行您的命令,我希望这可以为您解决此问题。

【讨论】:

  • 实际上,当我在 Mac 上安装 Expo-CLI 时,我一直在寻找解决该错误的解决方案,结果证明您的回答对我有所帮助。以前我收到这样的错误消息:npm ERR!在 '...elfsigned":"^1.9.1","' 附近解析时 JSON 输入意外结束
  • @wisnu Pramono,很高兴我的回答很有帮助。
【解决方案3】:

尝试使用以下命令清理 npm 缓存。这将清理您现有的 npm 条目并从头开始。我认为在安装过程中一个文件可能已损坏,这就是您遇到此问题的原因。

npm cache clean  

那就试试

npm install ionic -g

【讨论】:

    【解决方案4】:

    我遇到了这个问题。 当您卸载 node js 或删除 npm 全局包或在新机器上安装 node js 时会发生错误。

    请在安装npm installnpm i后安装全局npm包

    例如我的案例我已经卸载了 npm 全局包。当我安装 npm install 时,出现错误。

    【讨论】:

      【解决方案5】:

      您应该手动清除 npm 缓存文件,方法是转到 C:\Users[用户名]\AppData\Roaming\npm-cache 更改 [用户

      【讨论】:

      • 您的部分答案似乎缺失。
      【解决方案6】:

      我已经通过以下方式解决了这个问题:

      npm cache clean --force
      

      npm cache verify
      

      然后

      npm i npm@latest -g
      

      最后,我能跑了

      npm i
      

      【讨论】:

        猜你喜欢
        • 2021-01-04
        • 1970-01-01
        • 1970-01-01
        • 2020-09-18
        • 1970-01-01
        • 2020-09-11
        • 1970-01-01
        • 1970-01-01
        • 2020-11-01
        相关资源
        最近更新 更多