25

When I am trying to deploy a firebase project it shows an error message 'cannot find module firebase-functions' in npm console.The steps(node commands) I have done are:

  1. npm install -g firebase-tools
  2. firebase login
  3. firebase init

and finally where I stucked is
4. firebase deploy

Please help me.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Pradeep.T
  • 281
  • 2
  • 5
  • 7
  • 9
    Make sure you've installed node modules *in your functions directory*: `cd functions && npm install` – Michael Bleigh Apr 21 '17 at 17:48
  • 1
    Thanks ."cd functions" So is it necessary that there will be folder named functions? – Pradeep.T Apr 23 '17 at 15:10
  • Okey thanks. It worked.I could successfully deploy my project.But now when I enter the project url ,which is get from the hosting tab in firebase console, in browser it shows "Site not found" message.What else I should be done?Please reply. – Pradeep.T Apr 24 '17 at 05:02
  • I am having issues as well. Please see the following error: `Invalid name: "@types/jsonwebtoken"` Any clue? – narko Jul 24 '17 at 19:54

7 Answers7

12

It's simple! If it says can't find module firebase-functions then install them.

npm install firebase-functions
MasterScrat
  • 7,090
  • 14
  • 48
  • 80
Prajwal Waingankar
  • 2,534
  • 2
  • 13
  • 20
  • This is not a very good answer, especially considering that he is most likely in the wrong folder. – Pieter Jul 11 '19 at 22:23
  • He never said he was in a wrong folder. He was just not aware of the commands @Pieter – Prajwal Waingankar Jul 12 '19 at 07:37
  • If he knew then he woulnd't have the problem. It can be derived that he was in the wrong folder based on the steps he posted. Please note that my comment wasn't an insult to you but rather to serve as a warning to future readers to confirm the folder. – Pieter Jul 12 '19 at 07:50
  • sure @Pieter i m not taking it in a bad way :) Its nice that you shared yours opinion :) – Prajwal Waingankar Jul 12 '19 at 08:37
9

you should install node_modules in the functions directory in your project

cd functions
npm install 

then run firebase deploy

Amina Darwish
  • 328
  • 3
  • 5
  • 1
    I had just pulled a request from a security bot on GitHub and hadn't updated my functions, so this worked for me when I tried `firebase deploy` in the correct folder with no luck before trying this. The above command `npm install firebase-functions` didn't work, but changing directories did work. – Justin Jun 09 '20 at 15:19
6

Could be that you didn't follow the instructions provided when running "firebase init". You should press space and then enter in order to select the option you want - possibly that's why there was no functions folder.

1

This may happen if you have requires with wrong cases!

The firebase function file system seems to be case sensitive.

So if you do

const { myStuff } = require('./mystuff');

but the file is actually named myStuff.js, it may very well work locally, but fails on build

Jkarttunen
  • 6,764
  • 4
  • 27
  • 29
0

Try this

import * as admin from "firebase-admin";
Vaibhav Vishal
  • 6,576
  • 7
  • 27
  • 48
  • 2
    While your code may provide the answer to the question, please add context around it so others will have some idea what it does and why it is there. – Theo Aug 08 '19 at 15:28
0

I'm using @nrwl/nx monorepo and moved /functions to /apps and all my node pages are in the root project folder. What worked for me is to replace the double quotes with single quotes

import * as functions from "firebase-functions";

to

import * as functions from 'firebase-functions';
Abdullah Adeeb
  • 3,826
  • 1
  • 16
  • 14
0

I ran into this same issue scratching my head since I could clearly see firebase-functions in my package.json and it was definitely installed.

Then I remembered that I'm deploying (inherently production), and firebase-functions was in my devDependencies section of package.json instead of dependencies.

In case someone runs into this same issue, double check that firebase-functions is in dependencies as it won't be included in the resulting bundle or deployment otherwise. In my case, I needed to explicitly add it to my functions/package.json.

E.g. -> Move a module from devDependencies to dependencies in npm package.json

JDev518
  • 772
  • 7
  • 16