nachshon f
nachshon f

Reputation: 3670

Error with Firebase on Electron app: Failed to load gRPC

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.

Upvotes: 3

Views: 2102

Answers (2)

Felipe
Felipe

Reputation: 11959

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

Upvotes: 3

murgatroid99
murgatroid99

Reputation: 20277

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).

Upvotes: 6

Related Questions