-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can protobuf.js be used together with grpc-web? #1567
Comments
I think it's not possible, but it's better to ask grpc-web folks :) |
I solved my problem in the meanwhile by hacking protoc.exe to generate ES6 modules |
Not really as this module doesn't support streaming rpc methods properly - there's a PR to fix that here but it appears to have stalled: #1115 |
This might help: grpc/grpc-web#80 (comment) |
You might want to take a look at my nuget package https://www.nuget.org/packages/ArtsTech.Grpc.TypescriptClientGenerator/ |
@gunters63 can you help to share how to make protoc.exe generates es6 module? |
I have forked commit a1d8f8f9 of https://github.com/protocolbuffers/protobuf and patched ES6 support. It works for me and sorry, I never bothered to pull master again. Here is a patch: https://gist.github.com/gunters63/3c8798de46fa469e1ce06966df017ca8 If you want I can send you a Nextcloud link to Windows binaries I create my (Typescript) code with a command line like this:
|
Here a link: https://nextcloud.spranz.info/s/A7xHwmrbM6ByTnf The zip-Archiv also contains Linux binaries, but I never tested them. |
@gunters63 Thank you very much for this patch! This solved my search for a working Typescript version of my Stubs! I have added your Linux binaries into a Docker container from A few things I have noticed: import * as jspb from 'google-protobuf';
var goog = jspb;
var proto = {};
goog.exportSymbol('addition.AddRequest', null, proto);
...
export const {
AddRequest,
} = proto.addition; whereas on Linux I get: goog.exportSymbol('proto.addition.AddRequest', null, global); Without any exports... Currently I have 'hacked' my way around embedding your plugin into a custom Docker Entrypoint bash script to fetch all proto files and execute protoc on top, but this executes the commands on Linux and thus generates an 'invalid' JS file. Eventually, I should try to add it to their entrypoint instead. |
@nathansegers: Yeah, looks like the Linux binaries I uploaded where built from unpatched sources. I really don't understand why the protobuf team didn't implement ES6 support yet. It should be quite easy.. There is some initial support (header constants ...) in the sources already for years now. I suggest you clone the specific commit of protobuf, apply the patch and build the linux binaries yourself. |
Currently I'll just leave to work on Windows, which is fine for my situation ;-) |
This is an interesting alternative now: It does work with protoc-gen-grpc-web and supports ESM and is tree shakeable. |
I am currently using grpc-web in a React SPA-project.
The backend is implemented with gRPC for .NET, which already implements a middleware to translate gRPC-Web to gRPC HTTP/2 (like a built-in Envoy).
On the client side I use
protoc.exe
together with the grpc-web plugin (protoc-gen-grpc-web.exe
) to generate code for my services and for the proto serialization.protoc.exe
is currently not able to generate ES6 modules which is a bit problematic in my setup (I use Vite). Protobufjs seems to be better in this regard. Furthermore protobufjs claims to be several times faster with serialization/deserialization than theprotoc.exe
generated code. I would like to switch, but I would still have to keep grpc-web for the transport channel (multiplexing/framing) I think. My client code running in the browser has dozens of simultaneous server streaming subscriptions which is no problem with grpc-web and the protoc-generated code.So my question: Is it possible to use protobuf.js together with grpc-web?
The text was updated successfully, but these errors were encountered: