Dylan Steele
Dylan Steele

Reputation: 419

Issue adding Firebase to electron project, gRPC dependency issue

I have been having this issue for a couple days now and haven't been able to find a solution to it. From my research it seems that this is a known issue, but none of the provided fixes worked in my case.

I have tried:

npm rebuild

npm install grpc --runtime=electron --target=1.7.6

Another thing I tried was adding this to the package.json file:

  "resolutions": {
    "grpc": "^1.12.0"
  },

Also, I have tried changing versions of electron, grpc, firebase up and down.

The error I keep getting on console is:

E:\GitHub\Portfolio-Manager\node_modules\grpc\src\grpc_extension.js:53 Uncaught Error: Failed to load gRPC binary module because it was not installed for the current system
    Expected directory: electron-v1.7-win32-x64-unknown
    Found: [node-v59-win32-x64-unknown]
    This problem can often be fixed by running "npm rebuild" on the current system
    Original error: Cannot find module 'E:\GitHub\Portfolio-Manager\node_modules\grpc\src\node\extension_binary\electron-v1.7-win32-x64-unknown\grpc_node.node'
        at Object.<anonymous> (E:\GitHub\Portfolio-Manager\node_modules\grpc\src\grpc_extension.js:53)
        at Object.<anonymous> (E:\GitHub\Portfolio-Manager\node_modules\grpc\src\grpc_extension.js:63)
        at Module._compile (VM129 module.js:571)
        at Object.Module._extensions..js (VM129 module.js:580)
        at Module.load (VM129 module.js:488)
        at tryModuleLoad (VM129 module.js:447)
        at Function.Module._load (VM129 module.js:439)
        at Module.require (VM129 module.js:498)
        at require (VM130 module.js:20)
        at Object.<anonymous> (E:\GitHub\Portfolio-Manager\node_modules\grpc\src\client_interceptors.js:145)

Current dependencies:

  "dependencies": {
    "axios": "^0.16.1",
    "firebase": "^5.3.1",
    "flexboxgrid": "^6.3.1",
    "grpc": "^1.12",
    "nedb": "^1.8.0",
    "numeral": "^2.0.6",
    "vue": "^2.3.3",
    "vue-electron": "^1.0.6",
    "vue-router": "^3.0.1",
    "vue2-scrollbar": "0.0.3"
  },

Any kind of help would be appreciated.

Upvotes: 2

Views: 1644

Answers (3)

Max Ogden
Max Ogden

Reputation: 918

If you don't want to add a native module to your Electron app, you can use the commonjs bundles in Electron. Additionally, not every firebase sub-module requires grpc. In my case only firestore required grpc, so I could load my firebase components (auth and firestore) as follows:

var firebase = require('@firebase/app')
require('@firebase/auth') // populates firebase.default.auth
require('@firebase/firestore/dist/index.cjs.js') // populates firebase.default.firestore
firebase = firebase.default

Upvotes: 0

Dylan Steele
Dylan Steele

Reputation: 419

After a bit of research I found a command that rebuilds the binaries required correctly.

npm rebuild --runtime=electron --target=1.8.4 --disturl=https://atom.io/download/electron

As of this post for electron 1.8.* should work with this.

Upvotes: 8

DEDaniel
DEDaniel

Reputation: 231

Install 'electron-rebuild' in your devDependencies with

npm install --save-dev electron-rebuild

while being in your project folder run

npm prune && npm install && electron-rebuild

If this doesn't help would it be possible to install it globally with?

npm install -g grpc

Upvotes: 0

Related Questions