user_78361084
user_78361084

Reputation: 3888

undefined: grpc.ClientConnInterface when compiling grpc

I am new to grpc. In my go.mod file I have:

google.golang.org/genproto v0.0.0-20190508193815-b515fa19cec8
google.golang.org/grpc v1.21.1
github.com/gogo/protobuf v1.2.2-0.20190723190241-65acae22fc9d
github.com/golang/protobuf v1.3.2

I am generating my protobufs like this:

go get google.golang.org/protobuf/cmd/protoc-gen-go
go get google.golang.org/grpc/cmd/protoc-gen-go-grpc
protoc --go_out=. --go-grpc_out=. ./me.proto

I get the following errors when I try to run tests and build:

me_grpc.pb.go:15:11: undefined: grpc.SupportPackageIsVersion7
me_grpc.pb.go:25:5: undefined: grpc.ClientConnInterface
me_grpc.pb.go:28:30: undefined: grpc.ClientConnInterface
me_grpc.pb.go:65:34: undefined: grpc.ServiceRegistrar

I figured out that switching SupportPackageIsVersion7 to SupportPackageIsVersion5 makes gopls happy but I have no idea what I need to do in order to make the other errors go away. Unfortunately, I am stuck at the versions of the libraries in my go.mod file due to other things in my repo that fail to compile if I try to upgrade those libraries.

Upvotes: 4

Views: 6668

Answers (2)

ttrasn
ttrasn

Reputation: 4826

It's good that you started GRPC.

It seems like you're protoc-gen-go is old and needed to be updated,

to update it you should

  • first, remove the current one, to find where it is stored, you can use the echo $PATH command to find out where this file is. then remove it.

  • second, install the new one, for installing it you can run this command.

    go install google.golang.org/grpc/cmd/protoc-gen-go-grpc

    Note If you have any problem getting it, use this command instead,

    go get -u github.com/golang/protobuf/protoc-gen-go

after the update, you must edit your go.mod file.

change this line:

google.golang.org/grpc v1.21.1

to

google.golang.org/grpc v1.33.2

This version (1.33.2) supports SupportPackageIsVersion7 and your problem will be solved.

Note: SupportPackageIsVersion7 support after 1.32.0 versions. and they support old versions with go version >= 1.12

thanks, @bithavoc for the useful comment: to see the latest version, just look for the version on top of pkg.go.dev/google.golang.org/grpc

Upvotes: 6

Friedrich42
Friedrich42

Reputation: 752

replace (
   github.com/coreos/etcd => github.com/ozonru/etcd v3.3.20-grpc1.27-origmodule+incompatible
   google.golang.org/grpc => google.golang.org/grpc v1.27.0
)

in go.mod should help

Upvotes: 4

Related Questions