英文:
How to investigate/fix: ambiguous import: found package cloud.google.com/go/compute/metadata in multiple modules
问题
当我执行go mod tidy(go v1.19)时,我收到以下错误。我在我的go pkg目录中看到了这两个包。我假设v1.6.1是最新版本,并且是要保留的版本。如果这是正确的,我如何确定是谁引入了旧的v0.34.0版本并进行修正?我希望得到你的建议。
谢谢你的时间和关注,
Mike
github.com/abc/runimage/v5/core/service导入
github.com/grpc-ecosystem/go-grpc-middleware/auth由以下测试
github.com/grpc-ecosystem/go-grpc-middleware/auth.test导入
google.golang.org/grpc/credentials/oauth导入
golang.org/x/oauth2/google导入
cloud.google.com/go/compute/metadata:模糊导入:在多个模块中找到了cloud.google.com/go/compute/metadata包:
cloud.google.com/go v0.34.0(/Users/mike/Go/pkg/mod/cloud.google.com/go@v0.34.0/compute/metadata)
cloud.google.com/go/compute v1.6.1(/Users/mike/Go/pkg/mod/cloud.google.com/go/compute@v1.6.1/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
)
英文:
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/go@v0.34.0/compute/metadata)
cloud.google.com/go/compute v1.6.1 (/Users/mike/Go/pkg/mod/cloud.google.com/go/compute@v1.6.1/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
)
答案1
得分: 7
尝试运行go get cloud.google.com/go/compute/metadata
,然后运行go mod tidy
。
英文:
Try go get cloud.google.com/go/compute/metadata
and then go mod tidy
答案2
得分: 2
我遇到了和你一样的错误,我通过从我的go.mod
文件中删除cloud.google.com/go/compute/metadata
依赖项来解决了这个问题。在某个版本的Google Cloud API之后,它不再需要。
在我这样做之后,我运行了go mod tidy
,然后一切都重新开始工作了。
希望这能帮到你
英文:
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
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论