33

I am trying to host a app in firebase and its giving me error that

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

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

I have executed npm install command several times but nothing new.

enter image description here

Please help

5
  • Did you install the Firebase CLI? If you did, make sure you have the updated version. You can run npm install -g firebase-tools in your project directory Commented Mar 15, 2017 at 11:48
  • 1
    Yes i have done that Commented Mar 15, 2017 at 12:30
  • 2
    It looks like you forgot to run npm install (or npm install firebase) before deploying. See the last line of the terminal. Commented Mar 15, 2017 at 13:42
  • Also, make sure you're running npm install from the functions subdirectory of your project. Commented Mar 15, 2017 at 18:11
  • 4
    @MichaelBleigh I have done that several times Commented Mar 16, 2017 at 4:48

6 Answers 6

66

Cannot find module 'firebase-functions' means that you need to install packages. In your project directory run

$ cd functions
$ npm install

then return back and fire!

$ firebase deploy

Happy coding!

1
  • 1
    Still works! Appreciate it
    – Kuday
    Commented Nov 14, 2023 at 9:19
17

By default, the firebase dependency isn't in your functions/package.json. Instead, you'll find it lists firebase-admin, the specialized server-side Firebase SDK which is the one we recommend using.

If you really do want to use the firebase client-side SDK instead of firebase-admin, you'll want to run npm install --save firebase in your functions/ directory. You should then have a line in your functions/package.json that looks a bit like this:

{
  ...
  "dependencies": {
    "firebase": "^3.7.2",
    ...
  },
  ...
}
1
  • 1
    In my case, following the procedure above, the package.json did get updated with firebase dependency but I'm still getting the error: error TS2307: Cannot find module 'firebase' or its corresponding type declarations when I run firebase deploy. Can you tell me how to fix it? Commented Mar 28, 2023 at 3:38
5

Although this is coming late, but it's for those who might face the same issue. This worked for me. I added this to my package.json file in folder function.

 {
  "name": "functions",
  "description": "Cloud Functions for Firebase",
  "dependencies": {
    "firebase-admin": "~5.2.1",
    "firebase-functions": "^0.6.2",
    "mkdirp": "^0.5.1",
    "mkdirp-promise": "^4.0.0"
  },
  "private": true
}

Then run: npm install in folder function

1
  • @jason I'm happy it does. :)
    – Prodigy
    Commented Nov 22, 2017 at 11:25
4

Clean up node_modules,

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

Update functions/package.json file with latest or compatible versions of dependencies with your node version and run npm install from functions folder.

Try firebase deploy now. Should be good!

1
  • forgetting to do a clean up first was the problem for me, thanks
    – fkvestak
    Commented May 27, 2020 at 9:08
1

In my case, some of the cached packages were installed with root permission. So when I tried to deploy with only npm run deploy , was not finding the packages.

sudo npm run deploy worked for me.

0

first you have to select command prompt terminal instead of power shell ,then install npm within functions then run command npm start .

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.