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

Azure DevOps(原VSTS)仓库运行lerna-changelog报错:无法推断package.json的repo

解决lerna-changelog无法从Azure DevOps仓库推断repo的问题

我之前也碰到过一模一样的问题,lerna-changelog的默认仓库推断逻辑对Azure DevOps(原VSTS)的URL格式兼容性不太好,才会抛出Could not infer "repo" from the "package.json" file.这个错误。下面是几个亲测有效的解决办法:

方法1:在package.json中添加changelog专属配置

直接在项目根目录的package.json里手动指定repo信息,跳过工具的自动推断逻辑:

{
  // ... 其他已有字段
  "changelog": {
    "repo": "你的组织名/project_name"
  }
}

把这里的你的组织名替换成你Azure DevOps里的组织名称,project_name就是你的仓库名称即可。

方法2:完善package.json的repository字段

如果你的项目package.json里已经有repository字段,确保它的格式能被lerna-changelog识别。针对Azure DevOps仓库,你可以这样配置:

{
  // ... 其他已有字段
  "repository": {
    "type": "git",
    "url": "https://xxxxxxxxxxxxxxxx/DefaultCollection/project_name/_git/project_name"
  }
}

不过这个方法偶尔还是会因为Azure DevOps的特殊URL结构匹配失败,所以更推荐方法1的手动指定方式。

方法3:命令行参数临时指定

如果只是临时运行命令,不想修改配置文件,可以直接通过--repo参数强制指定:

lerna-changelog --repo=你的组织名/project_name

错误原因说明

查看lerna-changelog的configuration.ts源码就能发现,它的默认推断逻辑是用正则匹配GitHub、GitLab这类主流平台的仓库URL格式,而Azure DevOps的URL包含DefaultCollection、_git这类特殊路径片段,导致正则匹配失败,无法自动提取出owner/repo格式的仓库标识,所以必须手动配置来绕过这个问题。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.14 08:52:57