Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can`t make gRPC work with Electron.js

I`m making an Electron app that should connect by grpc to remote host and call some functions from there.

But I keep getting the following error: Uncaught Error: A dynamic link library (DLL) initialization routine failed. \?\D:\Projects\demo-app\node_modules\grpc\src\node\extension_binary\grpc_node.node

I tried to:

  1. establish grpc connection from main and from renderer processes of Electron
  2. install dependencies as npm install --unsafe-perm

    but nothing works.

Error

like image 567
juldepol Avatar asked Jul 09 '17 16:07

juldepol


2 Answers

The gRPC package is distributed with precompiled binaries for Electron, including on Windows, but you have to specify that you're using Electron when you do the installation. The following should work:

npm install grpc --runtime=electron --target=<electron version>
like image 133
murgatroid99 Avatar answered Oct 19 '22 18:10

murgatroid99


If you're using a native module, you'll need to rebuild them against your current electron node version.

There is a package called electron-rebuild that will do this for you. Basic instructions:

npm install --save-dev electron-rebuild

Then, whenever you install a new npm package, rerun electron-rebuild:

./node_modules/.bin/electron-rebuild

Or if you're on Windows:

.\node_modules\.bin\electron-rebuild.cmd
like image 6
mr.freeze Avatar answered Oct 19 '22 17:10

mr.freeze