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

执行Bazel build时出现版本错误:期望build_bazel_rules_typescript为0.21.0

解决Bazel build时build_bazel_rules_typescript版本不匹配错误

我之前也踩过这个版本对齐的坑,这个错误本质是WORKSPACE中声明的build_bazel_rules_typescript规则版本和npm依赖@bazel/typescript的版本不一致导致的,试试下面的步骤来修复:

1. 确认WORKSPACE中的规则版本

打开你的WORKSPACE文件,找到引入build_bazel_rules_typescript的代码块(通常是http_archive或者git_repository),确保版本明确指定为0.21.0,示例如下:

http_archive(
    name = "build_bazel_rules_typescript",
    url = "https://github.com/bazelbuild/rules_typescript/releases/download/0.21.0/rules_typescript-0.21.0.tar.gz",
    sha256 = "替换为该版本对应的SHA256哈希值",
)

提示:你可以在rules_typescript的release页面找到对应版本的sha256值

2. 同步npm依赖版本

打开package.json,找到@bazel/typescript的依赖项,将其版本修改为0.21.0,然后执行依赖安装命令:

# 如果你用npm
npm install
# 如果你用yarn
yarn install

3. 彻底清理并重新构建

虽然你已经试过部分清理命令,但再执行一次更彻底的清理流程:

bazel clean --expunge
rm -rf node_modules
rm -rf bazel-*  # 清理所有bazel生成的输出文件夹
npm install  # 重新安装依赖
bazel build //...  # 重新执行构建

4. 排查间接依赖冲突

如果以上步骤还没解决,检查是否有其他第三方规则间接引入了不同版本的build_bazel_rules_typescript,执行以下命令查看当前Bazel实际使用的规则版本:

bazel query --output=label //external:build_bazel_rules_typescript

如果输出的版本不是0.21.0,你需要在WORKSPACE中用override_repository强制指定版本:

override_repository(
    name = "build_bazel_rules_typescript",
    url = "https://github.com/bazelbuild/rules_typescript/releases/download/0.21.0/rules_typescript-0.21.0.tar.gz",
    sha256 = "对应的哈希值",
)

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.11 08:33:34