firebase-functions: Cannot find module 'grpc'

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

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Reactions: 3
  • Comments: 19 (6 by maintainers)

Most upvoted comments

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.

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'

Issue Resolved! In my case, I faced the same issue… I installed npm install -g firebase@4.6.2

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

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

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.