You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Ubuntu21.04环境下npm安装firebase报错FETCH_ERROR如何解决?

npm安装firebase报FETCH_ERROR解决方案

报错信息:
npm ERR! code FETCH_ERROR
npm ERR! errno FETCH_ERROR
npm ERR! invalid json response body at https://registry.npmjs.org/@grpc%2fgrpc-js reason: Unexpected end of JSON input

该错误本质是拉取@grpc/grpc-js依赖包时,npm获取到的包信息JSON不完整,常见原因包括本地缓存损坏、镜像源同步异常、网络代理配置错误,可按以下步骤排查修复:

  • 第一步:清理npm本地损坏缓存
    执行命令:
    npm cache clean --force
    清理完成后可执行npm cache verify确认缓存状态正常。
  • 第二步:调整npm镜像源
    优先使用官方源避免镜像同步不全问题,执行:
    npm config set registry https://registry.npmjs.org/
    若国内访问官方源速度慢,可切换到稳定国内镜像:
    npm config set registry https://registry.npmmirror.com/
    执行npm config get registry确认配置已生效。
  • 第三步:清理历史异常依赖文件
    删除当前项目下的node_modules文件夹和package-lock.json锁文件,执行:
    rm -rf node_modules package-lock.json
  • 第四步:重新执行安装
    先验证问题依赖是否可正常安装:
    npm i @grpc/grpc-js
    安装无报错后再执行firebase安装命令:
    npm i firebase

额外排查项

如果上述步骤仍未解决,可检查以下配置:

  • 确认npm没有配置错误的代理,执行以下命令清空代理配置:
    npm config delete proxy
    npm config delete https-proxy
  • 升级npm到最新稳定版本,避免旧版本npm的已知请求bug:
    npm install -g npm@latest

内容的提问来源于stack exchange,提问作者Fahim Ferdous

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 22:36:03