# go：缺少提供包 X 的模块的 go.sum 条目；要添加：go mod tidy

- **ID:** `go/go-mod-tidy-missing-go-sum-entry-for-module-providing-package`
- **领域:** go
- **类别:** build_error
- **验证级别:** ai_generated
- **修复率:** 98%

## 根因

go.sum 文件缺少当前模块所需依赖项的校验和，通常是在添加新导入或手动更新 go.mod 后发生。

## 版本兼容性

| 版本 | 状态 | 引入 | 弃用 |
|------|------|------|------|
| go1.20 | active | — | — |
| go1.21 | active | — | — |
| go1.22 | active | — | — |

## 解决方案

1. ```
   运行 'go mod tidy' 重新生成包含所有必需校验和的 go.sum
   ```
2. ```
   如果 go mod tidy 失败，先运行 'go mod download'，再运行 'go mod tidy'
   ```
3. ```
   对于使用 vendor 的项目，在 tidy 后运行 'go mod vendor' 以同步 vendor 目录
   ```

## 无效尝试

- **Manually edit go.sum to add the missing checksum** — go.sum is machine-generated and manual edits are overwritten or cause checksum mismatches (95% 失败率)
- **Delete go.sum and go.mod and start over** — Deletes all dependency info; may lose version constraints and cause other errors (80% 失败率)
- **Set GONOSUMCHECK=* to bypass checksum verification** — Disables security verification and is not portable across builds (50% 失败率)
