johanbrandhorst / protobuf

GopherJS Bindings for ProtobufJS and gRPC-Web
MIT License
81 stars 16 forks source link

Does not work with Node.js #41

Closed the729 closed 4 years ago

the729 commented 4 years ago

Works in Chrome browser. Does not works with Node.js. Output:

rpc error: code = Unknown desc = JavaScript error: Cannot read property 'protocol' of undefined

After disabling the error handling, I see the error is in grpc.inc.js, when client.start() is called.

johanbrandhorst commented 4 years ago

Hi! Glad you found the project. It doesn't support NodeJS, and frankly it probably never will. It would probably involve a lot of work and it's not really worth it. It's only intended to be run in browsers.

the729 commented 4 years ago

Can you please point some directions so that I can try to hack it a little bit?

My plan was to build a grpc.inc.js that could switch between grpc-web-node-http-transport and whatever transport for browsers. However, I can't even reproduce a working grpc.inc.js for browsers with the Makefile in grpcwebjs.

johanbrandhorst commented 4 years ago

What error are you getting? This project is kind of in maintenance mode, since GopherJS is pretty much moribound itself (it hasn't been updated for Go 1.13 or modules). I imagine it might be a problem with the grpc-web-client package name, I think we renamed it https://www.npmjs.com/package/@improbable-eng/grpc-web. Maybe that will fix it?

You're on the right track though, if you could build a grpc.inc.js that could switch transport it should be portable between node and the browser. I can't dedicate much time to this myself but I'll help you as much as I can.

the729 commented 4 years ago

42 fixes issue with the webpack config.

I also successfully generated a grpc.inc.js that works in node. However, I didn't figure out how to get both node and the browser to work with a single js file, because I have to use different targets (node vs web) in webpack.config.js.

Do you have any suggestions on this?

johanbrandhorst commented 4 years ago

Really cool to hear that you could get it working in node. I think we have to generate a single file and use some sort of runtime detection to decide what transport to use. That should be possible with GopherJS by looking at js.Global().Get("window") or however you do it in vanilla JS.