3

I'm building an Electron app, and in the renderer.js file, I'm using Firebase Admin to get Firestore data. However, whenever I run it, it returns this error in the logs..

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

I tried to run "npm rebuild", but it still didn't fix it. I also tried updating Firebase Admin and gRPC.

Here is the code from the renderer.js file...

// This file is required by the index.html file and will
// be executed in the renderer process for that window.
// All of the Node.js APIs are available in this process.

const admin = require('firebase-admin');

var serviceAccount = require('./credentials.json');

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount),
  databaseURL: "https://mytestapp.firebaseio.com"
});

var db = admin.firestore();
const settings = {
  timestampsInSnapshots: true
};
db.settings(settings);

function LoadList() {

  db.collection("Orders").get().then(function(Collection){

    Collection.forEach(function(OrderDoc){
      console.log(OrderDoc.id)
    })

  }).catch(function(err){
    console.error(err);
  });

}

document.querySelector('#ListSec').addEventListener('click', LoadOrderList)

Any ideas? I've been trying to solve this for hours, but can't seem to figure it out.

nachshon f
  • 3,540
  • 7
  • 35
  • 67
  • Possible duplicate of [NodeJs Error - Failed to load gRPC binary module because it was not installed for the current system Expected directory?](https://stackoverflow.com/questions/49758008/nodejs-error-failed-to-load-grpc-binary-module-because-it-was-not-installed-fo) – Martin Zeitler Sep 03 '18 at 23:33

2 Answers2

6

That error message indicates that gRPC was installed for Node, not for Electron. Electron has a different binary interface, so binary modules like gRPC need to be installed specifically for Electron. You can generally do this just by running npm rebuild --runtime=electron --target=2.0.0 (modified to match the version of Electron you want to use).

murgatroid99
  • 19,007
  • 10
  • 60
  • 95
  • is there an automated way to `npm install` while avoiding this problem? – Felipe Aug 03 '19 at 23:12
  • You could put the command I suggested in your installation script. Or maybe as a `postinstall` script/hook in your own `package.json` file. – murgatroid99 Aug 03 '19 at 23:55
3

The original answer by @murgatroid99 was helpful at the time, and a postinstall command worked great up until electron v7, where the issue returned.

For anyone else who comes across this issue, I've found a better solution:

the electron-rebuild package

npm install electron-rebuild --save-dev

Run it using

npx electron-rebuild

Or, add it as a postinstall command

{
  ...
  "scripts": {
    "postinstall": "electron-rebuild"
  },
  ...
}

Further information is in the official Electron Documentation

Community
  • 1
  • 1
Felipe
  • 10,606
  • 5
  • 40
  • 57