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

2

15

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
)
Volscian answered 9/9, 2022 at 8:26 Comment(3)
What's your go.mod file content?Disaffiliate
Hello Guillaume, Thank you for your response and interest. I've updated this question with the go.mod file's content. We are using go mod vendoring, too.Volscian
Did you try to explicitly define the metadata dependency in the go.mod?Disaffiliate
E
15

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

Ellynellynn answered 5/12, 2022 at 13:37 Comment(1)
Still getting ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules: cloud.google.com/go v0.26.0 (.../pkg/mod/cloud.google.com/[email protected]/compute/metadata) cloud.google.com/go/compute/metadata v0.2.3 (.../pkg/mod/cloud.google.com/go/compute/[email protected])Windsucking
F
2

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 :)

Festoon answered 25/2, 2023 at 4:15 Comment(0)

© 2022 - 2025 — McMap. All rights reserved.