gRPC is a modern open-source high-performance Remote Procedure Call (RPC) framework that can run in any environment. And in this article, I am goin...
For further actions, you may consider blocking this person and/or reporting abuse
If you having issues (like below) running the
buf generate
command.Use the protobuf-es.
Replace the content of your
buf.gen.yaml
file withThen run
npx buf generate
Excuse me, but this fails to generate the *.ts and *_grpc_pb.ts files. How do I have to modify buf.gen.yaml to get all files?
I noticed that if I do generate the _grpc_pb.js file (js instead of ts), I get the error:
SyntaxError: The requested module './proto/octants/v1/octants_grpc_pb' does not provide an export named 'DownloadOctantsService'
In my program this DownloadOctantsService is located in the _grpc_pb.js file and it is there, so apparently the reason for the error message is an incompatibility between JavaScript and TypeScript. Unfortunately translating the js file to ts using ChatGPT did not help since in that case, some methods referenced in the file are not found.
Great article. There are very few articles on typescript with gRPC.
I had to install
grpc_tools_node_protoc_ts
globally. Without it I got this errorFailure: plugin ts: could not find protoc plugin for name ts
running
buf generate --debug
gave this errorFailure: plugin grpc: exec: "grpc_tools_node_protoc_plugin": executable file not found in $PATH
and after installing globally buf generate works
If locally installed, node_modules/.bin has to be in path.
If instead of invoking it directly, we add an npm script to invoke it, then that will be taken care of by npm/yarn.
In package.json
Thanks for this tip. Didn't quite work for me until I copied the way the line above was structured:
"scripts": {
"start": "nodemon src/server/index.ts --watch src/server",
"start:client": "nodemon src/client/index.ts --watch src/client",
"proto:build": "cd proto; buf build; cd ..",
"codegen:buf": "cd proto; buf generate; cd .."
},
To get
npm run start
to work I had to also install ts-node like thisnpm i --dev ts-node
After
buf generare
got this errorMaybe someone could help?
Failure: plugin js: js moved to a separate plugin hosted at https://github.com/protocolbuffers/protobuf-javascript in v21, you must install this plugin; js moved to a separate plugin hosted at https://github.com/protocolbuffers/protobuf-javascript in v21, you must install this plugin
figured it out?
Do you know what "/" (slash) means?
If you are reffering to the text like
/src
,/
means the root directory of the project.Ah, that's the source of the confusion.
/
never actually means the root of a project. It's always the root of the filesystem.E.g. this:
should read:
proto/
: proto buffers folder(I will explain more later)src/
: the source directorysrc/server/
: server directorysrc/client/
: client directorysrc/proto/
: auto generated code from proto buffersYes, but when used in this manner it is generally regarded as the root of the project.