If you having issues (like below) running the buf generate command.
Failure: plugin js: js moved to a separate plugin hosted at https://github.com/protocolbuffers/protobuf-javascript in v21, you must install this plugin
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 error Failure: plugin ts: could not find protoc plugin for name ts
running buf generate --debug gave this error
Failure: plugin grpc: exec: "grpc_tools_node_protoc_plugin": executable file not found in $PATH
After buf generare got this error
Maybe 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
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:
/proto: proto buffers folder(I will explain more later) /src: the source directory /src/server: server directory /src/client: client directory /src/proto: auto generated code from proto buffers
should read:
proto/: proto buffers folder(I will explain more later) src/: the source directory src/server/: server directory src/client/: client directory src/proto/: auto generated code from proto buffers
If you having issues (like below) running the
buf generatecommand.Use the protobuf-es.
Replace the content of your
buf.gen.yamlfile withThen run
npx buf generateExcuse 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_tsglobally. Without it I got this errorFailure: plugin ts: could not find protoc plugin for name tsrunning
buf generate --debuggave this errorFailure: plugin grpc: exec: "grpc_tools_node_protoc_plugin": executable file not found in $PATHand 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 startto work I had to also install ts-node like thisnpm i --dev ts-nodeAfter
buf generaregot 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 pluginfigured 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.