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

npm更新自建Git私有包失败,报错code 128求解决

问题描述

环境:Windows 10 系统、Node.js v18.15.0
私有Git包托管于自建Bitbucket服务器,package.json中依赖配置为:

"my-package": "git+ssh://git@git:...."

执行npm update my-package命令时出现以下错误:

npm ERR! code 128
npm ERR! An unknown git error occurred
npm ERR! command git --no-replace-objects clone ssh://git@git:... ... --recurse-submodules -- config core.longpaths=true
npm ERR! Cloning into ...
npm ERR! fetch-pack: unexpected disconnect while reading sideband packet
npm ERR! fatal: early EOF
npm ERR! fatal: fetch-pack: invalid index-pack output

已尝试常规相关解决方案但无效,问题偶发,怀疑与网络因素有关。

排查与解决建议

1. 验证SSH连接稳定性

手动执行Git克隆命令测试:

git clone ssh://git@git:...

重复多次操作,确认是否同样出现EOF错误:

  • 若手动克隆也出错,优先调整Git/SSH配置:
    • 增大Git传输缓存并关闭压缩:
      git config --global http.postBuffer 524288000
      git config --global core.compression 0
      
    • 配置SSH保持连接:在C:\Users\<你的用户名>\.ssh\config文件中添加(无则新建):
      Host git
        ServerAliveInterval 60
        ServerAliveCountMax 5
        TCPKeepAlive yes
      
    • 临时切换HTTPS协议测试:修改package.json中的依赖为"my-package": "git+https://<用户名>:<访问令牌>@git:...,排除SSH层面问题

2. 优化npm相关配置

  • 强制清除npm缓存后重试:
    npm cache clean --force
    npm update my-package
    
  • 禁用子模块递归克隆(若无子模块依赖):
    npm update my-package --no-recurse-submodules
    

3. 服务器端排查(若有权限)

  • 检查自建Bitbucket服务器的网络带宽、CPU/内存负载,确认高峰时段是否存在资源耗尽导致连接中断
  • 查看Bitbucket系统日志,确认是否为服务器端主动断开连接

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 03:05:25