DEV Community

Discussion on: Use gRPC with Node.js and Typescript

Collapse
 
jkristia profile image
Jesper Kristiansen

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

and after installing globally buf generate works

Collapse
 
lorefnon profile image
Lorefnon

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

{ 
    "scripts":  {
        "codegen:buf": "buf generate"
    }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
rawnsley profile image
Rupert Rawnsley

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 .."
},