grpc / grpc-web

gRPC for Web Clients
https://grpc.io
Apache License 2.0
8.45k stars 760 forks source link

How to connect a docker-run Go gRPC server to a React app? #1425

Closed altjimmy closed 1 month ago

altjimmy commented 1 month ago

My first time here, doing a college project, have almost 0 experience with gRPC and web dev in general, so any advice is very much appreciated and please be patient with me.

The situation is: me and my classmate are building a web-module for loyalty service, i am making a client side, and he's working on server with Go and gRPC. I am using React and JS.

My classmate sent me a folder with all the files for the server, i did the docker-compose up, and it is running on my 44044 port. In my react app i generated two .js files from .proto file, ServiceLoyalty_pb.js and ServiceLoyalty_grpc_web_pb.js, they're stored in my src/generated folder.

But when i try to import it in my Page.jsx file (import { LoyaltyServiceClient } from '../../generated/ServiceLoyalty_grpc_web_pb';), the browser returns this: Uncaught SyntaxError: The requested module http://localhost:5173/src/generated/ServiceLoyalty_grpc_web_pb.js doesn't provide an export named: 'LoyaltyServiceClient' Operations.jsx:20:10

I checked the ServiceLoyaltyServiceLoyalty_grpc_web_pb,js file, it seems to be ok, but still my .jsx page refuses to see it and import it. Still, when hovering over the import, it seems to recognize it correctly image

What am i missing? Thank you in advance.