简体   繁体   中英

How to fix Go 1.11 module unknown import path, cannot find module providing package?

I am building a Go 1.11 Standard App Engine Service.

It's not under GOPATH , so I ran go mod init and go mod tidy .

I am able to build a simple web service using go build , and deploy and test using gcloud app deploy .

I am now trying to add gPubSub code to my service following this code example .

This adds the following imports: "context" , "cloud.google.com/go/pubsub" .

When I run go build , I get:

../../../../go/pkg/mod/golang.org/x/net@v0.0.0-20181217023233-e147a9138326/idna/idna.go:23:2: unknown import path "golang.org/x/text/secure/bidirule": cannot find module providing package golang.org/x/text/secure/bidirule
../../../../go/pkg/mod/golang.org/x/net@v0.0.0-20181217023233-e147a9138326/idna/idna.go:24:2: unknown import path "golang.org/x/text/unicode/bidi": cannot find module providing package golang.org/x/text/unicode/bidi
../../../../go/pkg/mod/golang.org/x/net@v0.0.0-20181217023233-e147a9138326/idna/idna.go:25:2: unknown import path "golang.org/x/text/unicode/norm": cannot find module providing package golang.org/x/text/unicode/norm

When I run go get -u all , I get "no Go files in"

go build golang.org/x/text/secure/bidirule: no Go files in
go build golang.org/x/text/unicode/bidi: no Go files in
go build golang.org/x/text/unicode/norm: no Go files in

cat go.mod shows me the following: ```

module github.com/XXX/YYY

require (
    cloud.google.com/go v0.34.0
    github.com/googleapis/gax-go v2.0.2+incompatible // indirect
    go.opencensus.io v0.18.0 // indirect
    golang.org/x/net v0.0.0-20181217023233-e147a9138326 // indirect
    golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890 // indirect
    golang.org/x/sync v0.0.0-20181108010431-42b317875d0f // indirect
    golang.org/x/sys v0.0.0-20181218192612-074acd46bca6 // indirect
    google.golang.org/api v0.0.0-20181220000619-583d854617af // indirect
    google.golang.org/appengine v1.3.0 // indirect
    google.golang.org/genproto v0.0.0-20181219182458-5a97ab628bfb // indirect
    google.golang.org/grpc v1.17.0 // indirect
)

```

go list . shows me the following:

go: finding golang.org/x/text/unicode/bidi latest
go: finding golang.org/x/text/secure/bidirule latest
go: finding golang.org/x/text/unicode/norm latest
go: finding golang.org/x/text/unicode latest
go: finding golang.org/x/text/secure latest
github.com/XXX/YYY/ZZZ (our project)

This seems to be some transient dependency.

When I deploy using gcloud app deploy , my service does successfully build and on execution, publishes to the pubsub topic, so this is a local problem.

How do I diagnose and fix this local dev environment problem?

固定:

rm -rf ~/go/pkg/mod/golang.org/x/text@v0.3.0

go get golang.org/x/text

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM