代码之家  ›  专栏  ›  技术社区  ›  nachshon f

电子应用程序上的FireBase出错:加载GRPC失败

  •  0
  • nachshon f  · 技术社区  · 6 年前

    我正在构建一个电子应用程序,在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
    

    我试图运行“NPM重建”,但它仍然没有修复它。 我还尝试更新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)
    

    有什么想法吗?我已经试着解决这个问题好几个小时了,但似乎还没弄清楚。

    1 回复  |  直到 6 年前
        1
  •  1
  •   murgatroid99 dhg    6 年前

    npm rebuild --runtime=electron --target=2.0.0