电子应用程序上的Firebase错误:无法加载gRPC

nac*_*n f 2 firebase grpc electron firebase-admin google-cloud-firestore

我正在构建一个Electron应用程序,并且在renderer.js文件中,我正在使用Firebase Admin获取Firestore数据。但是,无论何时运行它,它都会在日志中返回此错误。

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
Run Code Online (Sandbox Code Playgroud)

我试图运行“ npm rebuild”,但是它仍然没有解决。我还尝试更新Firebase Admin和gRPC。

这是renderer.js文件中的代码...

// 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)
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我已经尝试解决了几个小时,但似乎无法弄清楚。

mur*_*d99 6

该错误信息表明gRPC是为Node安装的,而不是为Electron安装的。Electron具有不同的二进制接口,因此需要专门为Electron安装二进制模块(例如gRPC)。通常,您可以通过运行npm rebuild --runtime=electron --target=2.0.0(修改以匹配您要使用的Electron的版本)来执行此操作。