grpc / grpc/grpc-node

grpc-tools grpc output references protobuf files that were not created

Open
#2,297 14 comments 0 reactions 0 assignees View on GitHub
package: grpc-tools
Dominant language
TypeScript
Stars
4.8k
Forks
716
Avg merge
2d 3h
Merged PRs (30d)
10

Description

### Problem description
I encountered a head scratcher (maybe not a bug) my first time trying to use grpc-node's packages.

`foo_grpc_pb.js` seems to reference pb models at `foo_pb.js`, except the models are each created in their own js module, without a comprehensive `_pb.js`.

### Reproduction steps

With the `package.json` and `reservations.proto` files below, I run the command `npm run protoc`, which is: `grpc_tools_node_protoc ./reservations.proto --proto_path=. --js_out=. --grpc_out=.`

I would expect to see output for protobuf models and the grpc service that references the generated protobuf sources. The file `reservations_grpc_pb.js` references the file `reservations_pb.js` with a `require`. However, I only see `reservationopresult.js`, `reservationidentifier.js` and `reservation.js` files created for protobuf.

If the command is correct but the output is incorrect, this should probably be handled as an error state. Am I missing a config option? I see `generate_package_definition` and `grpc_js` in `grpc-node/packages/grpc-tools/src/node_plugin.cc` that I didn't encounter in the docs or guides.

`./package.json`
```
{
"name": "learning-protobuf-and-grpc-js",
"scripts": {
"protoc": "grpc_tools_node_protoc ./reservations.proto --proto_path=. --js_out=. --grpc_out=."
},
"dependencies": {
"@grpc/grpc-js": "^1.8.0"
},
"devDependencies": {
"grpc-tools": "^1.12.3"
}
}

```

`./reservations.proto`
```
syntax = "proto3";

service Reservations {
rpc CreateReservation(Reservation) returns (ReservationOpResult) {}
}

message Reservation {
string when = 1;
uint32 id = 1;
}

message ReservationOpResult {
bool success = 1;
optional string error = 2;
}
```

### Environment
- OS name, version and architecture: OSX 13.0.1
- Node version 18.12.1
- Node installation method: Installer from Nodejs.org's downloads page
- If applicable, compiler version: N/a
- Package name and version: grpc-tools 1.12.3

### Additional context

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.