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

使用Yarn安装内部Gitlab私有NPM包返回404 Not Found问题求助

问题原因与解决方案
  • 原因1:认证token权限不匹配
    你的.npmrc中仅配置了项目ID为819的私有包访问token,但报错的@mypackage/lib-node-common包托管在项目ID为725的仓库下,当前使用的token没有725项目的npm包读取权限。浏览器能访问是因为你的登录账号拥有725项目权限,和Yarn使用的token权限相互独立。
    解决方案:在.npmrc中新增725项目的auth配置,或者给当前使用的token开通725项目的包读取权限:
    //gitlab.intra/api/v4/projects/725/packages/npm/:_authToken=xxxxx
    
  • 原因2:Yarn本地缓存的认证或元信息过时
    Yarn本地缓存了旧的包元数据和认证状态,会导致请求时携带错误信息。
    解决方案:执行以下命令清理缓存后重试安装:
    yarn cache clean
    rm -rf node_modules yarn.lock
    yarn add @mypackage/lib-node-client
    
  • 原因3:Yarn v1版本兼容性Bug
    Yarn经典版(v1.x)对Gitlab多项目NPM Registry的认证传递逻辑存在已知问题,请求tar包时不会自动带上全局Registry的认证头。
    解决方案:
    1. 升级到Yarn v3+(Berry版本),在.yarnrc.yml中配置统一的私有Registry地址
    2. 临时添加--always-auth参数执行安装:yarn add @mypackage/lib-node-client --always-auth
    3. 改用npm执行安装验证是否为Yarn本身的问题:npm install @mypackage/lib-node-client

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.09.29 02:54:02