Module found but does not contain package

Issue

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.

Solution

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

Answered By – cdugga

Answer Checked By – Katrina (GoLangFix Volunteer)

Leave a Reply

Your email address will not be published.