-
Notifications
You must be signed in to change notification settings - Fork 597
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
Stop loading proto files dynamically #2936
Comments
How important is it to separate the proto files from the main build files in Node.js? Your proposal seems to suggest dynamic JSON loading in Node.js, and a static bundle for the browser. Usually we find the converse - that it is the browser where you want the granular loading of JSON files, and in Node.js where it is better to have everything in one file for their performance. |
@guybedford So the problem here with the underlying library (gRPC) that for now cannot consume the statically created proto object. So we'll try to see how JSON protos performs in both cases (both Node and browser). I can write more words but let me better share some code that will show the idea :) (later this week) |
Any update here? I'm having issues with webpack & google cloud node client |
Greetings! If you're having issues, please file a new issue letting us know specifically what you're trying, and what problems you're running into :) I don't think this is the issue you're looking for :P |
@timconnorz Just an update, we've been loading protos from a pre-compiled JSON for a year already, and we have a Thank you! |
Currently, all gRPC Node.js client libraries load proto files dynamically using @grpc/proto-loader (that internally calls
protobufjs.loadSync
). Since proto files can form a huge dependency tree, it brings some real time complexity to the client constructor, and (more importantly) it blocks things like webpack (#2933).There are several possible ways to deal with this dynamic load.
[proposed option] Compile protos to JSON using
pbjs -t json
running in apostinstall
script, and load this JSON file in the runtime. For Node.js, this JSON format can be read by@grpc/proto-loader
without making any changes to it (it's an undocumented feature but sinceprotobufjs
supports it,@grpc/proto-loader
also supports it). For browsers, we'll doprotobuf.root.fromJSON(jsonContent)
to load the same JSON file which will berequire
d to become a part of the bundle.Compile proto files to static objects with
protoc
- this is what other languages do.I dislike this option, mostly because the change from
protobufjs
object toprotoc
will likely bring some incompatibilities and hard-to-find bugs in the libraries.Compile proto files to static objects with
pbjs
. Unfortunately, static objects generated bypbjs -t static-module
are not supported by@grpc/grpc-js
so we can't use this option for now (even though it's a great option for possible browser usage).So, from my undestanding at this moment, the first option is the only option that would allow us to make the code working both in Node.js without dynamic proto loading, and in browsers (with no gRPC support). I'm going to work on this option and will update this issue when the code is ready to review.
Cc: @JustinBeckwith @bcoe @guybedford
The text was updated successfully, but these errors were encountered: