google/protobuf.dart

Error: Couldn't find constructor 'GrpcServiceName'.

wheeOs opened this issue · 9 comments

wheeOs commented

My proto dart files are generated by protoc_plugin version 21.0.2 with

protoc --version
libprotoc 3.21.8 
(also tried libprotoc 24.0)

on Mac OS (M1)

I thought that this wouldn't happen and got fixed by #848 or #844 but it isn't unfortunately.
I don't know if I'm missing something

Here is a sample snippet:

@$pb.GrpcServiceName('verification.VerificationService')
class VerificationServiceClient extends $grpc.Client {
...

the respective error:

lib/src/generated/proto/verification.pbgrpc.dart:22:6: Error: Couldn't find constructor 'GrpcServiceName'.
@$pb.GrpcServiceName('verification.VerificationService')
     ^^^^^^^^^^^^^^^
wheeOs commented

for the time being, is there any possibility to use an older version of protoc_plugin? I couldn't figure out how to activate the plugin globally with a specific version other than the latest.

I was able to work around this in my project by manually overriding from protobuf 2 to 3 by adding the following to my pubspec.yaml:

dependency_overrides:
  protobuf: ^3.0.0
wheeOs commented

@CaseyHillers thank you for sharing this! Finally a workaround.. that fixed it!

@wheeOs

I couldn't figure out how to activate the plugin globally with a specific version other than the latest.

For next time:

$ dart pub global activate --help
Make a package's executables globally available.

Usage: dart pub global activate <package> [version-constraint]

So for example:

> dart pub global activate protoc_plugin 20.0.1

Will install v. 20.0.1

wheeOs commented

@sigurdm
ah ... I was trying to do it via flutter pub global activate protoc_plugin@20.0.1 instead 🤦🏻‍♂️
Thanks for pointing that out!

ah ... I was trying to do it via flutter pub global activate protoc_plugin@20.0.1 instead 🤦🏻‍♂️

Yeah, that would also make sense given the new pub add syntax.