Firebase-functions: Cannot find module 'grpc'

Created on 9 Nov 2017  Â·  19Comments  Â·  Source: firebase/firebase-functions

After I added the firebase functions and trying to deploy an angular app into firebase I got this:

i  deploying firestore, functions, hosting
i  firestore: checking firestore.rules for compilation errors...
✔  firestore: rules file firestore.rules compiled successfully
i  functions: ensuring necessary APIs are enabled...
i  runtimeconfig: ensuring necessary APIs are enabled...
✔  runtimeconfig: all necessary APIs are enabled
✔  functions: all necessary APIs are enabled
i  firestore: uploading rules firestore.rules...
i  functions: preparing functions directory for uploading...

Error: Error parsing triggers: Cannot find module 'grpc'

Try running "npm install" in your functions directory before deploying.

Are there any resolution or workaround to this?

My env is
node 8.9.0
npm 5.5.1
firebase 3.14.0

Most helpful comment

I'm was runninginto a similar error trying to run firebase functions locally, and I found something that may address this for you @Lacka90.

In my case, I was running n to select version 6.11.1 of npm, but typically I use yarn to manage my projects (as well as higher versions of node in other projects).

I suspect that was a part of the problem, since I may have installed dependencies with yarn install at some point out of habit.

The specific error I was getting was:

Cannot find module '/[...local path...]/functions/node_modules/grpc/src/node/extension_binary/node-v48-darwin-x64/grpc_node.node'

If I inspect the missing path above, it's got node-v57-darwin-x64/grpc_node.node (note v57 vs the v48 that the firebase call is looking for.

To fix
I cleared my node_modules directory, and reinstalled using npm install to be sure everything came from npm, and not yarn. This installed the correct version of grpc, and I no longer had that error to deal with.

All 19 comments

Just to confirm, did you run npm install from inside the functions directory?

Additionally, it's recommended that you run Node v.6.11.1 because that's the version which will be running your code in the Cloud Functions environment, as mentioned here.

Yes I made npm install in the functions directory.

I tried again with node v6.11.1. but the same error message appears :(
I'm trying to follow the tutorial to make an universal angular app:
https://hackernoon.com/deploy-angular-universal-w-firebase-ad70ea2413a1

What's in your package.json? Does the npm install succeed?

I'm was runninginto a similar error trying to run firebase functions locally, and I found something that may address this for you @Lacka90.

In my case, I was running n to select version 6.11.1 of npm, but typically I use yarn to manage my projects (as well as higher versions of node in other projects).

I suspect that was a part of the problem, since I may have installed dependencies with yarn install at some point out of habit.

The specific error I was getting was:

Cannot find module '/[...local path...]/functions/node_modules/grpc/src/node/extension_binary/node-v48-darwin-x64/grpc_node.node'

If I inspect the missing path above, it's got node-v57-darwin-x64/grpc_node.node (note v57 vs the v48 that the firebase call is looking for.

To fix
I cleared my node_modules directory, and reinstalled using npm install to be sure everything came from npm, and not yarn. This installed the correct version of grpc, and I no longer had that error to deal with.

Thanks for sharing the fix!

@laurenzlong I can confirm that the above fix does not work for me.

For me this is happening because a npm module that I use relies on the firebase client library. It appears the firebase client library has a side-effect of breaking firebase-admin.

I've been working on debugging this one as well and I believe it's related to https://github.com/firebase/firebase-tools/issues/442 and possibly https://github.com/firebase/firebase-js-sdk/issues/221#issuecomment-337103110 as per the comment.

This worked form me (I reinstalled firebase tool and update the firebase-functions):-
npm install -g firebase-tools
npm install firebase-functions@latest --save

@factedu I tried what you suggested. Did not work for me :(

@connormckelvey What versions of npm are you using? Can you try updating it and see if it resolves the issue?

I have tried npm versions 5.4 and 3.2 and node versions 8.9.2 and 6.9 and the problem is the same .
"Cant find grpc module ".
Tried every possible written solutions.
None worked for me as well.

I am using npm 5.5.1 and had problems with grpc at deploying. I installed firebase-admin@~5.5.0 and everything seems to work normally now.

Will have to try it out as now i am working on mac os sierra.

This is the repo for grpc node: https://github.com/grpc/grpc-node. Please file specific installation issues there.

In my experience, grpc installation issues can usually be resolved by a combination of updating npm and reinstalling, but the grpc team may be able to offer more specific advice.

We are capturing all grpc installation issues experienced in Firebase CLI in https://github.com/grpc/grpc-node/issues/121

Issue Resolved!
In my case, I faced the same issue...
I installed
npm install -g [email protected]

and removed cap ^ in package.json before firebase version.

hopeItWillWorkForYou

Solved! I had a very similar error and it worked for me when I used
npm install grpc@latest --save
in the functions directory.
In my case it could not find a specific file and showed the error as
Error: Error parsing triggers: Cannot find module '<path_to_my_firebase_functions>/node_modules/grpc/src/node/extension_binary/node-v57-linux-x64-glibc/grpc_node.node'

In my case I had a package-lock.json file with some items that were no longer needed. I did

rm package-lock.json
rm -rf node_modules
npm install

and the problem went away

Was this page helpful?
0 / 5 - 0 ratings

Related issues

iouhammi picture iouhammi  Â·  24Comments

alexbjorlig picture alexbjorlig  Â·  66Comments

peterpeterparker picture peterpeterparker  Â·  53Comments

beeirl picture beeirl  Â·  46Comments

stasbar picture stasbar  Â·  33Comments