模块找到但不包含包

huangapple go评论71阅读模式
英文:

Module found but does not contain package

问题

我在使用Go时遇到了依赖问题,想要了解一下根本原因,希望有人能给予一些指导。

我在我的Go项目中使用了Prometheus的Go客户端(https://github.com/prometheus/client_golang)作为依赖。它有一个被称为xxhash的传递性依赖,可以通过Go的模块感知版本通过github.com/cespare/xxhash/v2的虚拟路径进行发现。看起来这个实用程序最近更新为使用go模块,并且通过其v2后缀来指示。

我正在使用模块模式下的go 1.17.7,并且使用默认的GoPath。当我尝试运行go mod tidy时,返回以下错误。

github.com/cespare/xxhash/v2: module github.com/cespare/xxhash/v2@latest found (v2.1.2), but does not contain package github.com/cespare/xxhash/v2

我正在使用模块模式,并且这是一个传递性依赖,所以我期望go会在$GOPATH\pkg\mod\cache\download\github.com\cespare\xxhash\v2\@v中查找该版本。我确实在那个精确的文件夹中看到了缓存的版本。然而,我还注意到go为相同的依赖项创建了一个目录$GOPATH\pkg\mod\github.com\cespare\xxhash\v2@v2.1.2,但源代码尚未下载。

我阅读了其他帖子,其中解决方法是升级到一个新版本的Go,该版本支持模块,或者升级Prometheus客户端的版本。然而,在这种情况下,我已经使用了每个依赖项的最新版本。

英文:

I have a dependency issue with Go and was trying to understand the root cause, hopefully someone can shed some light.

I'm using the Prometheus go client ( https://github.com/prometheus/client_golang ) as a dependency in my Go project. This has a transitive dependency called xxhash, which is discoverable by module aware versions of Go through the virtual path of github.com/cespare/xxhash/v2. It looks like this utility was recently updated to use go modules and this is indicated by its v2 suffix.

I'm running go 1.17.7 in module mode and using the default GoPath. When I try to run go mod tidy it returns the following error.

github.com/cespare/xxhash/v2: module github.com/cespare/xxhash/v2@latest found (v2.1.2), but does not contain package github.com/cespare/xxhash/v2

I'm running in module mode and this is a transitive dependency so I expect that go will look in $GOPATH\pkg\mod\cache\download\github.com\cespare\xxhash\v2\@v to find that version. I do see that version cached in that precise folder. I also notice however that go creates a directory for the same dependency at $GOPATH\pkg\mod\github.com\cespare\xxhash\v2@v2.1.2 but the source has not been downloaded.

I've read other threads where this was resolved by upgrading to a newer version of Go which was module aware , or alternatively upgrading the version of the Prometheus client however in this case I'm on the latest for each.

答案1

得分: -1

原始的GOPATH配置使用了一个镜像代理,即Artifactory,用于依赖解析。由于校验和冲突,无法拉取所有的依赖项。我改回了proxy.golang.org来解决这个问题。

英文:

The original GOPATH configuration was using a mirror proxy, in the form of Artifactory, for dependency resolution. Checksum collisions prevented pulling in all dependencies. I reverted to proxy.golang.org to resolve the issue

huangapple
  • 本文由 发表于 2022年3月3日 01:37:56
  • 转载请务必保留本文链接:https://go.coder-hub.com/71326945.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定