执行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
相关产品推荐
相关产品推荐

