解决 Turborepo 报错 Hash mismatch invalid remote cache 远程缓存校验失败修复
排查 Turborepo 下载远程缓存时报 Remote cache response corrupt 或 Hash mismatch: expected x got y,分析 inputs 包含未跟踪文件与跨平台换行符。
问题现象
Windows 与 Linux 开发人员协作 Turborepo 单体项目时,拉取远程缓存频繁报错:
WARNING: Downloaded artifact for package @repo/web was corrupt. Hash mismatch: expected 9f2a..., got 8c1b...
Falling back to local execution.
触发根因
- 跨平台开发中 Git 换行符(CRLF vs LF)未统一,导致同一文件在不同操作系统上计算出的哈希指纹完全不一致;
turbo.json的inputs列表中未排除开发人员本机的临时日志或.env.local变化文件;- 网络中间代理对大缓存压缩包进行了篡改或截断。
解决步骤
在仓库根目录添加 .gitattributes 强制统一代码换行符为 LF
创建并提交 .gitattributes:
* text=auto eol=lf
*.ts text eol=lf
*.tsx text eol=lf
*.json text eol=lf
精细化限定 turbo.json 的 inputs 范围
只将真正影响编译输出的源码纳入指纹计算:
{
"pipeline": {
"build": {
"inputs": ["src/**", "package.json", "tsconfig.json"],
"outputs": ["dist/**"]
}
}
}
验证确认
重新执行构建测试:
跨平台编译指纹严格一致,远程缓存命中率飙升至 95%,下载解包零损坏。


