I'm creating a simple gRPC client but I'm getting the error:
Error: TypeError: HelloService is not a constructor
at grpcCall (...)
js code:
const grpc = require('@grpc/grpc-js');
const protoLoader = require('@grpc/proto-loader');
...
const HelloService = grpc.loadPackageDefinition(packageDefinition).HelloService;
const client = new HelloService('grpcb.in:9000', grpc.credentials.createInsecure()); // <-- error here
proto file:
syntax = "proto2";
package hello;
service HelloService {
rpc SayHello(HelloRequest) returns (HelloResponse);
rpc LotsOfReplies(HelloRequest) returns (stream HelloResponse);
rpc LotsOfGreetings(stream HelloRequest) returns (HelloResponse);
rpc BidiHello(stream HelloRequest) returns (stream HelloResponse);
}
message HelloRequest {
optional string greeting = 1;
}
message HelloResponse {
required string reply = 1;
}
Turns out, I need to include the
packagename from the proto file i.e.package hello;. So, I need to change the lineto
Took me a while to figure it out. I feel the error message could have been much better, like: