Closed bcmills closed 1 year ago
Change https://go.dev/cl/496518 mentions this issue: cmd/go: add a test that reproduces an unstable 'go mod tidy'
This is related to #27899, but simpler in that it only requires preserving existing versions of modules (not upgrading to newer versions).
Change https://go.dev/cl/496635 mentions this issue: cmd/go: retain extra roots to disambiguate imports in 'go mod tidy'
@gopherbot, please backport to Go 1.19 and 1.20. This bug causes go mod tidy
to produce go.mod
files that then fail on subsequent go mod tidy
invocations. That happens only rarely, but the failure mode is confusing and the workarounds are not obvious.
Backport issue(s) opened: #60351 (for 1.19), #60352 (for 1.20).
Remember to create the cherry-pick CL(s) as soon as the patch is submitted to master, according to https://go.dev/wiki/MinorReleases.
Change https://go.dev/cl/499635 mentions this issue: [release-branch.go1.20] cmd/go: retain extra roots to disambiguate imports in 'go mod tidy'
Change https://go.dev/cl/499636 mentions this issue: [release-branch.go1.19] cmd/go: retain extra roots to disambiguate imports in 'go mod tidy'
Change https://go.dev/cl/502695 mentions this issue: cmd/go/internal/modload: address comment and test issues from CL 496635
I'm still seeing a similar issue when running go mod tidy
, using the current tip of 1.19 (9a2e6c9cc2ffa970b8ac5ecf0ea272415e1d9e03).
github.com/coinhako/superwallet/bch imports
github.com/btcsuite/btcd/chaincfg imports
github.com/btcsuite/btcd/chaincfg/chainhash: ambiguous import: found package github.com/btcsuite/btcd/chaincfg/chainhash in multiple modules:
github.com/btcsuite/btcd v0.22.0-beta (/home/ubuntu/go/pkg/mod/github.com/btcsuite/btcd@v0.22.0-beta/chaincfg/chainhash)
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 (/home/ubuntu/go/pkg/mod/github.com/btcsuite/btcd/chaincfg/chainhash@v1.0.1)
@RaghavSood, the go mod tidy
change only helps if the package is unambiguous to begin with. You need to go get
one of those modules or the other to tell it which to use, and then go mod tidy
should preserve that choice going forward.
I did try that by running the go get github.com/btcsuite/btcd/chaincfg/chainhash@v1.0.1
, but it still results in the same error upon go mod tidy
Do both the btcd
and chainhash
modules appear explicitly in your go.mod
file? If they do, you'll need to upgrade or downgrade one or the other of them to a version that does not contain the ambiguous package.
Only btcd
is directly referenced in go.mod - chainhash is pulled in as an indirect dependency by other packages I depend on
ubuntu@sw-raghav-dev:~/dev/superwallet$ grep btcsuite go.mod
github.com/btcsuite/btcd v0.23.4
github.com/btcsuite/btcutil v1.0.3-0.20201208143702-a53e38424cce
Ah, then perhaps you don't have lazy module loading enabled? (Does your go.mod
file indicate go 1.17
or higher?)
@bcmills could this maybe still be an issue in the transitive case?
test_gomod_bug imports
my.private.package imports
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc tested by
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc.test imports
google.golang.org/grpc/interop imports
golang.org/x/oauth2/google imports
cloud.google.com/go/compute/metadata: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules:
cloud.google.com/go v0.65.0 (/go/pkg/mod/cloud.google.com/go@v0.65.0/compute/metadata)
cloud.google.com/go/compute/metadata v0.2.3 (/go/pkg/mod/cloud.google.com/go/compute/metadata@v0.2.3)
But my.private.package
has an // indirect
entry for cloud.google.com/go/compute/metadata
(which was being pruned before #60352, but is now correctly left).
So before the fix, repeated go mod tidy
would fail in my.private.package
, but now it fails on packages that import it.
I expected the // indirect
dep to satisfy the requirement you mentioned, no?
You need to go get one of those modules or the other to tell it which to use
@costela, consumers of my.private.package
may still need to go get
a specific module to disambiguate when they first add the dependency. #27899 is the issue for that more general problem.
go get github.com/btcsuite/btcd/chaincfg/chainhash
works now as chainhash just upgraded to v1.0.2.
go: upgraded github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1 => v1.0.2
What version of Go are you using (
go version
)?Does this issue reproduce with the latest release?
Yes.
What operating system and processor architecture are you using (
go env
)?go env
OutputWhat did you do?
Clone vocdoni/census3@559b89d34e19824f0027a0724c136f9cac694673 and
go mod tidy
it twice:What did you expect to see?
Both
go mod tidy
operations should succeed.What did you see instead?
The first
go mod tidy
succeeds, but it removes a requirement needed to prevent an ambiguous import in a test dependency of a transitively-imported package, causing the secondgo mod tidy
to fail:(CC @matloob)
Example courtesy of @mvdan.