英文:
Go modules: checksum mismatch
问题
最近我开始在Go中使用模块,但经常遇到这样的问题:在一台机器上一切正常,但在另一台机器上构建代码库时遇到了校验和不匹配的问题。
问题总是涉及相同的第三方依赖项(github.com/ericlagergren/decimal):
go: 验证 github.com/ericlagergren/decimal@v0.0.0-20181231230500-73749d4874d5: 校验和不匹配
下载的: h1:HQGCJNlqt1dUs/BhtEKmqWd6LWS+DWYVxi9+Jo4r0jE=
go.sum: h1:x4oNpFLLl+8l+iLgksNHzZewTS0SKp6m0hlLwzXRbqA=
我尝试了各种方法:删除并重新生成go.sum
,将Go本身升级到最新的补丁版本,并从go.mod
中删除依赖项,但似乎没有解决这个问题。
有人知道如何解决这个问题吗?
英文:
I recently started using modules in Go, but I frequently encounter issues where everything works fine on one machine, but a checksum mismatch is encountered when building the codebase on another machine.
The issue always concerns the same third party dependency (github.com/ericlagergren/decimal):
go: verifying github.com/ericlagergren/decimal@v0.0.0-20181231230500-73749d4874d5: checksum mismatch
downloaded: h1:HQGCJNlqt1dUs/BhtEKmqWd6LWS+DWYVxi9+Jo4r0jE=
go.sum: h1:x4oNpFLLl+8l+iLgksNHzZewTS0SKp6m0hlLwzXRbqA=
I've tried various things: removing & regenerating go.sum
, upgrading Go itself to the latest patch version and removing the dependency from go.mod
but nothing seems to fix this issue.
Does anyone have an idea how to fix this issue?
答案1
得分: 57
你可以运行go clean -modcache
,然后运行go mod tidy
,这将使用正确的校验和重新下载所有的依赖项(这将更新$GOPATH/pkg/mod/
中的包缓存)。
要更新vendor/
文件夹,请运行:go mod vendor
。
英文:
You can run go clean -modcache
and then go mod tidy
which will re-download all deps with the correct checksum (this updates the pkg cache in $GOPATH/pkg/mod/
).
To update vendor/
folder run: go mod vendor
.
答案2
得分: 21
- 删除 go.sum 文件:rm go.sum
- 重新生成 go.sum 文件:go mod tidy
英文:
- remove go.sum : rm go.sum
- regenerate go.sum : go mod tidy
答案3
得分: 12
你使用的是哪个版本的Go?很有可能你遇到了1.11.2 -> 1.11.4
的问题后果:
- https://github.com/golang/go/issues/27093
- https://github.com/golang/go/issues/27925
- https://github.com/golang/go/issues/29278
这个问题还没有完全解决。请记住,go mod
仍在开发中,所以类似这样的问题可能会一直发生,直到1.13版本。
请确保了解Go的小版本发布以及这些问题可能发生的情况:https://github.com/golang/go/wiki/MinorReleases
> TL;DR - 升级Go
英文:
Which version of Go are you using? There's a good chance you're running into the aftermath of the 1.11.2 -> 1.11.4
:
- https://github.com/golang/go/issues/27093
- https://github.com/golang/go/issues/27925
- https://github.com/golang/go/issues/29278
Which still isn't completely resolved. Remember that go mod
is still in development, so things like this will probably happen up and until 1.13.
Be sure to read up on minor releases for Go, and how these things can happen: https://github.com/golang/go/wiki/MinorReleases
> TL;DR - Upgrade Go
答案4
得分: 1
我遇到了这个问题是因为GOPROXY的原因,通过更改代理地址解决了这个问题。
英文:
I encountered this problem because of the GOPROXY, and the problem was solved by changing the proxy address.
答案5
得分: 0
我在使用1.12.8版本时遇到了同样的问题,清除缓存也没有帮助。原来我仍然被困在GOPATH和Mod世界的中间。我在另一个帖子(https://stackoverflow.com/questions/55664630/how-do-i-migrate-from-dep-to-go-modules)中找到了一个标志,对我很有帮助。
go run -mod=vendor main.go
英文:
I was having the same problem using 1.12.8 and no cache cleaning would help. Turns out I am still locked in the middle of GOPATH and the Mod world. I found a flag in another post (https://stackoverflow.com/questions/55664630/how-do-i-migrate-from-dep-to-go-modules) that did the trick for me.
go run -mod=vendor main.go
答案6
得分: 0
我遇到了同样的问题。我更新了Go版本,并从go.mod中删除了导入项,还从go.sum中删除了所有条目,然后运行了"go mod tidy"命令,它成功下载了所有依赖项。
英文:
I had the same issue. I updated the go version and removed the imports from go.mod and removed all entries from go.sum and ran go mo tidy, which downloaded all the dependencies without any issues.
答案7
得分: 0
你需要从go.sum文件中删除你的包。如果你是通过终端模式、使用CI/CD或Dockerfile运行的,你可以使用以下的sh命令:
sed '/^github.com\/ericlagergren\/decimal@/d' ./go.sum > temp.txt && mv temp.txt go.sum
这个命令的作用是:
- sed - Unix应用程序
- '/^ - 从行首开始匹配
- github.com\/hyperledger\/fabric v1.4.4 - 你的包名(实际上是一个正则表达式,用**\转义了/**)
- /d' - 表示删除该行
- go.sum - 我们的Go语言sum文件
- > temp.txt - 将输出保存到临时文件
- mv temp.txt go.sum - 用临时文件覆盖我们的go.sum文件
附注:go mod tidy
只会删除未使用的包并添加新版本,但不会删除旧版本。
英文:
You need to delete your package from the go.sum file.
If you run from terminal mode, using CI/CD or Dockerfile you can use that sh command:
sed '/^github.com\/ericlagergren\/decimal@/d' ./go.sum > temp.txt && mv temp.txt go.sum
Which does:
- sed - unix application
- '/^ - starts line from
- github.com\/hyperledger\/fabric v1.4.4 - your package name (actually RegEX line, shield / with \)
- /d' - means delete line
- go.sum - our golang sum file
- > temp.txt - save output to temporary file
- mv temp.txt go.sum - rewrite our go.sum with temporary file
P.S.: go mod tidy
- only removes unused packages and add new versions. But it doesn`t delete olders.
答案8
得分: 0
你可以尝试这样做:
$ go get sigs.k8s.io/controller-runtime@v0.14.1
go: 正在下载 sigs.k8s.io/controller-runtime v0.14.1
正在验证 sigs.k8s.io/controller-runtime@v0.14.1/go.mod: 校验和不匹配
下载的: h1:GaRkrY8a7UZF0kqFFbUKG7n9ICiTY5T55P1RiE3UZlU=
go.sum: h1:G7mAYYxgmS0lVkHyy2hEOLQCFB0DlQFTMLWggykrydY=
在模块缓存中删除相关文件
# rm -rf ~/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.1/
# rm ~/go/pkg/mod/cache/download/sigs.k8s.io/controller-runtime/@v/v0.14.1.zip
# rm ~/go/pkg/mod/cache/download/sigs.k8s.io/controller-runtime/@v/v0.14.1.info
# rm ~/go/pkg/mod/cache/download/sigs.k8s.io/controller-runtime/@v/v0.14.1.mod
# rm ~/go/pkg/mod/cache/download/sigs.k8s.io/controller-runtime/@v/v0.14.1.lock
# rm ~/go/pkg/mod/cache/download/sigs.k8s.io/controller-runtime/@v/v0.14.1.ziphash
英文:
you can try like this:
$ go get sigs.k8s.io/controller-runtime@v0.14.1
go: downloading sigs.k8s.io/controller-runtime v0.14.1
verifying sigs.k8s.io/controller-runtime@v0.14.1/go.mod: checksum mismatch
downloaded: h1:GaRkrY8a7UZF0kqFFbUKG7n9ICiTY5T55P1RiE3UZlU=
go.sum: h1:G7mAYYxgmS0lVkHyy2hEOLQCFB0DlQFTMLWggykrydY=
remove the relate file on the mod cache
# rm -rf ~/go/pkg/mod/sigs.k8s.io/controller-runtime@v0.14.1/
# rm ~/go/pkg/mod/cache/download/sigs.k8s.io/controller-runtime/@v/v0.14.1.zip
# rm ~/go/pkg/mod/cache/download/sigs.k8s.io/controller-runtime/@v/v0.14.1.info
# rm ~/go/pkg/mod/cache/download/sigs.k8s.io/controller-runtime/@v/v0.14.1.mod
# rm ~/go/pkg/mod/cache/download/sigs.k8s.io/controller-runtime/@v/v0.14.1.lock
# rm ~/go/pkg/mod/cache/download/sigs.k8s.io/controller-runtime/@v/v0.14.1.ziphash
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论