3

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.

user_78361084
  • 3,538
  • 22
  • 85
  • 147

2 Answers2

5

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

ttrasn
  • 4,322
  • 4
  • 26
  • 43
  • 1
    Thank you but I am unable to upgrade to a better version. I have a LOT of dependencies that are out of my control that I am unable to upgrade. – user_78361084 Nov 15 '20 at 16:56
  • 1
    @user_78361084 Did you try to change this line `google.golang.org/grpc v1.21.1`? – ttrasn Nov 15 '20 at 18:33
  • Like I said, I am not able to upgrade any of my packages. I have to build with what is in the go.mod file. Changing that line causes a lot of issues in other packages. – user_78361084 Nov 17 '20 at 00:42
  • 2
    @user_78361084 This update hadn't any conflict with older versions. Your old version is `1.21.1` that supports `SupportPackageIsVersion5`, the version `1.33.2` also support `SupportPackageIsVersion from 3 to 7`. so you are free to use the new version – ttrasn Nov 17 '20 at 06:03
  • Why does it generate version 7, though? – user_78361084 Nov 17 '20 at 19:19
  • 1
    @user_78361084 `grpc.SupportPackageIsVersion` is used to track the version of the protobuf generated code and is different from the grpc release version. – ttrasn Nov 17 '20 at 20:36
  • 1
    to see the latest version, just look for the version on top of https://pkg.go.dev/google.golang.org/grpc – bithavoc Dec 19 '22 at 10:53
4
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

Friedrich42
  • 752
  • 4
  • 10
  • I got away with fixing all errors by just updating the `google.golang.org/grpc` to `v1.27.0` – Timmy May 04 '21 at 19:29