grpc / grpc-web

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

--js_out=import_style=commonjs doesn't export the messages from _pb.js files #1186

Closed chris-kruining closed 2 years ago

chris-kruining commented 2 years ago

the _pb.js files generated with the commonjs import style do not define module.exports. how can I import my message classes in my code so I can construct a request message for example?

currently I have this "build path":

CI of repo Library.Proto generates the stubs for web and c# and commits these to the respective repo CI of repo Library.Proto.Typescript builds the received typesctript files and bundles it all into a lib. npm install that-lib import the message class into business logic

sampajano commented 2 years ago

Hi! Thanks for the question!

You're right that the _pb.js file doesn't directly contain module.exports statements.. Although, they contain goog.exportSymbol(...) statements which i believe will export the message classes into module space too.

See our common-js code examples on how import statements looks like, and the related Dockerfile on how the code is generated and bundled (using webpack).

Lemme know if you still have issues after seeing the examples! Thanks! :)

chris-kruining commented 2 years ago

I fixed the issue with custom plugin that just generates typescript for me. so this is no longer relevant for me. Still, thank you for answering 😊

sampajano commented 2 years ago

Of course! Glad it works for you now! Thank you for letting us know! :)