使用gqlgen生成GraphQL schema时出现missing go.sum entry错误求助
解决gqlgen生成Schema时的missing go.sum entry错误
问题重现
执行gqlgen生成命令:
go run github.com/99designs/gqlgen generate
出现以下错误:
..\..\..\..\..\go\pkg\mod\github.com\99designs\gqlgen@v0.17.33\main.go:20:2: missing go.sum entry for module providing package github.com/urfave/cli/v2 (imported by github.com/99designs/gqlgen); to add: go get github.com/99designs/gqlgen@v0.17.33 ..\..\..\..\..\go\pkg\mod\github.com\99designs\gqlgen@v0.17.33\codegen\field.go:16:2: missing go.sum entry for module providing package golang.org/x/text/cases (imported by github.com/99designs/gqlgen/codegen); to add: go get github.com/99designs/gqlgen/codegen@v0.17.33 ..\..\..\..\..\go\pkg\mod\github.com\99designs\gqlgen@v0.17.33\codegen\field.go:17:2: missing go.sum entry for module providing package golang.org/x/text/language (imported by github.com/99designs/gqlgen/codegen); to add: go get github.com/99designs/gqlgen/codegen@v0.17.33 ..\..\..\..\..\go\pkg\mod\github.com\99designs\gqlgen@v0.17.33\internal\imports\prune.go:15:2: missing go.sum entry for module providing package golang.org/x/tools/go/ast/astutil (imported by github.com/99designs/gqlgen/internal/imports); to add: go get github.com/99designs/gqlgen/internal/imports@v0.17.33 ..\..\..\..\..\go\pkg\mod\github.com\99designs\gqlgen@v0.17.33\internal\code\packages.go:14:2: missing go.sum entry for module providing package golang.org/x/tools/go/packages (imported by github.com/99designs/gqlgen/codegen/config); to add: go get github.com/99designs/gqlgen/codegen/config@v0.17.33 ..\..\..\..\..\go\pkg\mod\github.com\99designs\gqlgen@v0.17.33\internal\imports\prune.go:16:2: missing go.sum entry for module providing package golang.org/x/tools/imports (imported by github.com/99designs/gqlgen/internal/imports); to add: go get github.com/99designs/gqlgen/internal/imports@v0.17.33
原因分析
这类错误是因为go.sum文件缺少gqlgen及其子模块依赖的校验条目,Go模块需要这些条目验证依赖包的完整性和一致性,避免依赖被篡改。
解决步骤
- 安装指定版本的gqlgen,补全主模块的sum条目:
go get github.com/99designs/gqlgen@v0.17.33
- 自动整理所有依赖,补全缺失的sum条目并清理无用依赖:
go mod tidy
- 重新执行gqlgen生成命令:
go run github.com/99designs/gqlgen generate
内容的提问来源于stack exchange,提问作者judith herlambang
相关产品推荐
相关产品推荐

