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

Time:01-18

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.

CodePudding user response:

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.

  • Related