go build_error ai_generated true

go:缺少提供包 X 的模块的 go.sum 条目;要添加:go mod tidy

go: missing go.sum entry for module providing package X; to add: go mod tidy

ID: go/go-mod-tidy-missing-go-sum-entry-for-module-providing-package

其他格式: JSON · Markdown 中文 · English
98%修复率
90%置信度
1证据数
2023-05-10首次发现

版本兼容性

版本状态引入弃用备注
go1.20 active
go1.21 active
go1.22 active

根因分析

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

English

The go.sum file is missing checksums for a dependency required by the current module, often after adding a new import or updating go.mod manually.

generic

官方文档

https://go.dev/ref/mod#go-sum-files

解决方案

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

无效尝试

常见但无效的做法:

  1. Manually edit go.sum to add the missing checksum 95% 失败

    go.sum is machine-generated and manual edits are overwritten or cause checksum mismatches

  2. Delete go.sum and go.mod and start over 80% 失败

    Deletes all dependency info; may lose version constraints and cause other errors

  3. Set GONOSUMCHECK=* to bypass checksum verification 50% 失败

    Disables security verification and is not portable across builds