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

已删除的Npm包仍在registry中,Bitbucket安装失败求替代方案

解决npm优先从registry安装已删除包、忽略Bitbucket源的问题

问题背景

4-5个月前发布过transaction-handler-ts的npm包,之后删除了该包,改为从Bitbucket直接安装,用命令npm install bitbucket:dummy/transaction-handler-ts#develop。之前安装正常,但现在执行该命令时弹出错误:npm ERR! Cannot convert undefined or null to object。排查发现npm还能从registry.npmjs.org找到这个本该删除的包,导致直接忽略Bitbucket源,下载空内容失败。目前已经靠改包名为transaction-handler-ts-two解决了问题,现寻求其他可行方案,同时已经联系了npm官方。

其他可行解决方案

  • 强制指定安装源,跳过registry检查
    执行安装命令时加上参数,强制npm不从公共registry拉取,直接用Bitbucket源:

    npm install bitbucket:dummy/transaction-handler-ts#develop --no-registry
    

    或者临时指定Bitbucket的API作为registry:

    npm install bitbucket:dummy/transaction-handler-ts#develop --registry=https://bitbucket.org/api/1.0/repositories/
    
  • 在package.json里配置包源映射
    针对npm 8及以上版本,在项目的package.json中添加overrides字段,强制指定transaction-handler-ts的安装来源:

    {
      "overrides": {
        "transaction-handler-ts": "bitbucket:dummy/transaction-handler-ts#develop"
      }
    }
    

    配置完成后直接运行npm install,npm就会优先拉取Bitbucket上的版本。

  • 清理本地npm缓存
    本地缓存可能残留了已删除包的旧信息,先清理缓存再重新安装:

    npm cache clean --force
    

    缓存清理后再执行原安装命令,避免本地缓存干扰源的选择。

  • 给Bitbucket包添加scope命名空间
    修改Bitbucket仓库里package.json的name字段为@dummy/transaction-handler-ts(加上自定义scope),这样npm会把带scope的包和公共registry上的无scope同名包区分开,安装命令不变:

    npm install bitbucket:dummy/transaction-handler-ts#develop
    

    此时npm会优先匹配指定的Bitbucket源,不会去公共registry查找同名包。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.27 07:32:55