menu

Questions & Answers

What is the recommended way to do a grpc call from inside a Typescript Vue.Js component?

After reading the documentation of grpc I see proto files can generate Node (Javascript), Typescript with plugin grpc_tools_node_protoc_ts and grpc-web. Since performance is not critical in my case I can load the .proto files with proto-loader. What are the advantages of using each of the 3 approaches for my case and what would you recommend?

I tried using the Javascript Node default generator but I got trouble making it work with Vue.Js, I get the error: "ReferenceError: process is not defined" when I load the package resources with grpc-js latest version ("@grpc/grpc-js": "^1.8.4"). Then I started wondering if I chose the right approach in the first place.

Comments:
2023-01-17 23:20:09
The TypeScript code and the JavaScript code are going to be identical, only differing in optional type annotations which will be compiled away. Therefore you may want to rethink the source of your problems. You talk of generating TypeScript, but TypeScript itself generates JavaScript.
Answers(1) :

For web environment you should not use proto-loader instead use directly either grpc-web or protobuf-ts/plugin, both support web browser calls. I would actually today recommend protobuf-ts/plugin since I had a known issue with grpc-web lib.