A Bit of Help
A Bit of Help

Reputation: 1766

How to investigate/fix: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules

When I do a go mod tidy (go v1.19), I am receiving the following error. I do see both packages in my go pkg directory. I assume that v1.6.1 is the most current version and is the one to keep. If this is true, how do I determine who is dragging in the older v0.34.0 version and correct it? I'd appreciate your suggestions.

Thank you for your time and interest, Mike

github.com/abc/runimage/v5/core/service imports
    github.com/grpc-ecosystem/go-grpc-middleware/auth tested by
    github.com/grpc-ecosystem/go-grpc-middleware/auth.test imports
    google.golang.org/grpc/credentials/oauth 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.34.0 (/Users/mike/Go/pkg/mod/cloud.google.com/[email protected]/compute/metadata)
    cloud.google.com/go/compute v1.6.1 (/Users/mike/Go/pkg/mod/cloud.google.com/go/[email protected]/metadata)
make: *** [tidy] Error 1
// go.mod 

module github.com/abc/runimage/v5

go 1.19

require (
    github.com/grpc-ecosystem/go-grpc-middleware v1.3.0
    github.com/labstack/gommon v0.3.1
    google.golang.org/genproto v0.0.0-20220805133916-01dd62135a58
    google.golang.org/grpc v1.48.0
    google.golang.org/protobuf v1.28.1
)

require (
    github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.2
    github.com/joho/godotenv v1.4.0
)

require (
    github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.0-20210816181553-5444fa50b93d // indirect
    github.com/go-resty/resty/v2 v2.7.0 // indirect
    github.com/goccy/go-json v0.9.4 // indirect
    github.com/golang/protobuf v1.5.2 // indirect
    github.com/hashicorp/errwrap v1.0.0 // indirect
    github.com/hashicorp/go-multierror v1.1.1 // indirect
    github.com/lestrrat-go/backoff/v2 v2.0.8 // indirect
    github.com/lestrrat-go/blackmagic v1.0.0 // indirect
    github.com/lestrrat-go/httpcc v1.0.0 // indirect
    github.com/lestrrat-go/iter v1.0.1 // indirect
    github.com/lestrrat-go/jwx v1.2.18 // indirect
    github.com/lestrrat-go/option v1.0.0 // indirect
    github.com/mattn/go-colorable v0.1.12 // indirect
    github.com/mattn/go-isatty v0.0.14 // indirect
    github.com/okta/okta-jwt-verifier-golang v1.3.1 // indirect
    github.com/patrickmn/go-cache v0.0.0-20180815053127-5633e0862627 // indirect
    github.com/pkg/errors v0.9.1 // indirect
    github.com/valyala/bytebufferpool v1.0.0 // indirect
    github.com/valyala/fasttemplate v1.2.1 // indirect
    golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d // indirect
    golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
    golang.org/x/sys v0.0.0-20220610221304-9f5ed59c137d // indirect
    golang.org/x/text v0.3.7 // indirect
)

Upvotes: 18

Views: 12654

Answers (4)

KevBurnsJr
KevBurnsJr

Reputation: 4878

For me, the error I got was coming from some generated gRPC code:

ambiguous import: found package google.golang.org/genproto/googleapis/rpc/status in multiple modules

I had to delete the package from ~/go/pkg and then go get:

sudo rm -rf ~/go/pkg/mod/google.golang.org/genproto/googleapis
go get google.golang.org/genproto

I had to sudo the rm -rf because the file permissions were whack. Maybe the root cause? Not sure.

Upvotes: 0

Mohammad Fatemi
Mohammad Fatemi

Reputation: 1298

I've faced a similar issue in my project but with a different dependency.

Generally, what I've done was to run

go mod graph > graph.out

# or using grep I guess

go mod graph | grep cloud.google.com/[email protected]

And search for the ambiguous module within graph.out (cloud.google.com/[email protected] in your case). Then just run

go get -u {dependent_module}

Upvotes: 1

Aphix
Aphix

Reputation: 306

I had the same error as you, and I resolved it by deleting the cloud.google.com/go/compute/metadata dependency from my go.mod file. It isn't needed after a certain version of the google cloud api.

After I did that, I ran go mod tidy and everything started to work again.

Hope this helps :)

Upvotes: 3

Maxim Vladimirsky
Maxim Vladimirsky

Reputation: 1259

Try go get cloud.google.com/go/compute/metadata and then go mod tidy

Upvotes: 17

Related Questions