2
votes

Installed [email protected] (also tried @4.0.7) and installed grpc and @grpc/proto-loader. When I launch electron I get a runtime error

Uncaught Error: Failed to load gRPC binary module because it was not installed for the current system Expected directory: electron-v4.0-darwin-x64-unknown Found: [node-v64-darwin-x64-unknown] This problem can often be fixed by running "npm rebuild" on the current system

Of course I tried running the suggested solution, npm rebuild, but that did not solve the problem. I also tried rebuilding the grpc module

npm rebuild grpc --build-from-source --runtime=electron --target=4.0.0 --target_archx64 --dturl=https://atom.io/download/electron

I tried uninstalling everything and starting from scratch. We're cloning the electron quick start repo and so after cloning and installing modules I installed grpc targeting a specific version

npm install grpc --runtime=electron --target=<electron version>

Which resulted in the same error so then I tried rebuilding

npm install --save-dev electron-rebuild // to rebuild grpc module

And if I delete node_modules and package-lock.json and then re-install npm install I get a success message (don't pay attention to the version, I'm watching my versions are matching) which looks like the "missing" module was installed

node-pre-gyp WARN Using request for node-pre-gyp https download [grpc]

Success: "/../electron/node_modules/grpc/src/node/extension_binary/node-v64-darwin-x64-unknown/grpc_node.node" is installed via remote

[email protected] postinstall /../electron/node_modules/protobufjs node scripts/postinstall

[email protected] postinstall /../electron/node_modules/electron node install.js

1
You are building for Electron 4.0.0 but installing Electron 4.0.8. Not sure if that could cause the error, though. Maybe you should rebuild grpc after installing it (and after installing electron-rebuild) ? - Seblor
No, when I install a specific version of electron I target that version. The last install jumped to @4.0.8 for some reason - islalobo
I redid everything. I'm cloning the electron quick start repo and now it's @4.0.7 and getting the same error that grpc was compiled against a different node version NODE_MODULE_VERSION 64 vs NODE_MODULE_VERSION 69 - islalobo
Do you compile grpc as the last thing before starting the app ? Also, why do you leave <electron version> in the npm install grpc command, instead of giving the version like you do in the first command ? - Seblor
It's pseudo code. I put the target in the command. - islalobo

1 Answers

0
votes

I found the answer here: https://github.com/grpc/grpc-node/issues/762

Still, the solution I tried is the solution I needed. Not sure what I was doing wrong initially!

For future Googlers the summary is this:

The grpc_node module seems to be compiled for NODE_MODULE_VERSION=64, but Electron 4 since 4.0.4 switched ... to specifying NODE_MODULE_VERSION=69 and there is a mismatch at runtime trying to load the module.

So, what I did to solve was

  • Clone the electron quick start repo
  • Uninstall the version of electron that came with quick start
  • Install [email protected]
  • Install gRPC with target to 4.0.0

    npm install grpc --runtime=electron --target=4.0.0