grpc-node: Electron OSX build: grpc is unable to load Google proto files
I’m working on an electron 5.x app. The dev build works fine, but the prod build is broken.
When I start the app, a blank screen appears and I get this error:
Error: ENOENT: no such file or directory, open 'google/protobuf/api.proto'
This happens when I’m trying to create an OSX build using electron-builder. The build process is successful and there are no errors. The resulting asar file contains the node_modules dir as it should and grpc seems to be installed properly.
But somehow the paths seem to be messed up in the prod build. Any suggestions on what could be wrong? How should I fix this?
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Comments: 28 (10 by maintainers)
I ran into this issue as well. I am using Webpack and merely imported
@google-cloud/storage
and bam! The app broke in production:It took quite a while to figure out what’s going on.
The simple fix
Here’s my simple fix for those who are facing this issue and Google still hasn’t fixed the
@grpc/proto-loader
library, which is a dependency of the@google-cloud/storage
.Update your
webpack.config.js
to have a new loader (specify it first):Then create file
scripts/remove-proto-loader-protos.js
with the following code:That’s it! The proto loading code will be automatically wiped out. No need for separate forks and keeping them updated manually.
This of course means that if anyone needs those proto files, you have to load them manually (look above at @mrfelton’s comment). Also, if Google updates their code, this hack may need to be updated in the future. I know, this is a hack, but what can you do?
¯\_(ツ)_/¯
Is it really necessary to hardcode the loading of the google proto files into the proto-loader codebase?
If someone wants to use those definitions can’t the do so by loading themselves?
@gtamas checkout
@ln-zap/proto-loader
and see if that works for you as they already made a fork for the same situation (building in an electron + webpack project)I managed to fix the issue with this Webpack config: