Ryan Tin
Ryan Tin

Reputation: 431

NodeJS: protoc generated files not generating service definition

Have a relatively simple helloworld.proto file down below

syntax = "proto3";

package helloworld;

service Greeter { rpc SayHello(HelloRequest) returns (HelloResponse); }

message HelloRequest { string name = 1; }

message HelloResponse { string message = 1; }

When I run protoc --js_out=import_style=commonjs,binary:. .\helloworld.proto it generates a helloworld_pb.js file but it doesn't include my Greeter service nor my SayHello rpc function. Looked around a few other post and also Google's reference (https://developers.google.com/protocol-buffers/docs/reference/overview) and it seems like I need to include a --plugin option but I can't seem to find any. Does anybody have a solution to for this?

Upvotes: 0

Views: 2580

Answers (2)

Arjanno
Arjanno

Reputation: 11

For those that have been looking for an example that also generates typescript see below

grpc_tools_node_protoc.cmd --js_out=import_style=commonjs,binary:.\output --grpc_out=generate_package_definition:.\output *.proto

grpc_tools_node_protoc.cmd  --plugin=protoc-gen-ts.cmd=./node_modules/.bin/protoc-gen-ts --ts_out=.\typescript -I .\output *.proto

Upvotes: 1

murgatroid99
murgatroid99

Reputation: 20297

The protoc plugin for Node gRPC is distributed in the grpc-tools npm package. That package provides a tool grpc_tools_node_protoc that is a version of protoc that automatically includes the plugin.

As described in that package's README, when you run the tool you will also need to use the --grpc_out argument to control the plugin. The question is tagged grpc-js, so you will probably want to use the grpc_js option for that argument to generate code that interacts with grpc-js.

Upvotes: 3

Related Questions