DEV Community

sdcaulley
sdcaulley

Posted on

1 1

Gotcha with Generated Files and Clients

When using [grpc-tools](https://www.npmjs.com/package/grpc-tools) to create generated Node.js files, you have three options the --grpc_out flag:

  • grpc_js: Generates code with require('@grpc/grpc-js') instead of require('grpc')
  • generate_package_definition: Generates code that does not require any gRPC library, and instead generates PackageDefinition objects that can be passed to the loadPackageDefinition function provided by both the grpc and @grpc/grpc-js libraries.
  • no option: Generates code with require('grpc')

Using the grpc_js or no option actually triggers protoc to create a generic client in the *_grpc_pb.js file:

exports.RouteGuideClient = grpc.makeGenericClientConstructor(RouteGuideService);
Enter fullscreen mode Exit fullscreen mode

What I found was that you need to use the same instance of gRPC (not just the same version) for them to work together. This will not be a problem if you are declaring you protos, generated files, and clients all in the same project. However, I have mine spread in different npm packages, so I did not use this functionality.

Sentry image

Hands-on debugging session: instrument, monitor, and fix

Join Lazar for a hands-on session where you’ll build it, break it, debug it, and fix it. You’ll set up Sentry, track errors, use Session Replay and Tracing, and leverage some good ol’ AI to find and fix issues fast.

RSVP here →

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay