Pradeep.T
Pradeep.T

Reputation: 321

Error shows 'cannot find module firebase-functions' when deploying a firebase project

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.

Upvotes: 29

Views: 25788

Answers (7)

JDev518
JDev518

Reputation: 778

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

Upvotes: 0

Abdullah Adeeb
Abdullah Adeeb

Reputation: 4316

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';

Upvotes: 0

Jkarttunen
Jkarttunen

Reputation: 7631

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

Upvotes: 2

Prajwal Waingankar
Prajwal Waingankar

Reputation: 2718

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

npm install firebase-functions

Upvotes: 12

Mahesh Yadav
Mahesh Yadav

Reputation: 11

Try this

import * as admin from "firebase-admin";

Upvotes: 0

Amina Darwish
Amina Darwish

Reputation: 466

you should install node_modules in the functions directory in your project

cd functions
npm install 

then run firebase deploy

Upvotes: 11

Marianna Panteli
Marianna Panteli

Reputation: 228

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.

Upvotes: 6

Related Questions