16

This question is essentially the same as question 44799104, only that I provide my index.js (and the only answer there was not helpful, as I do include 'exports').

In short, I have deployed my function successfully,

Console output

but it does not show in the console. Where am I going wrong? Here is my index.js:

const functions = require('firebase-functions');
const admin = require('firebase-admin');

admin.initializeApp(functions.config().firebase);

var delayInMilliseconds = 5000;


exports.copyRoom= functions.database.ref('/RoomsOwn/${AuthUid}').onWrite((event) => {

    var uid = event.params.AuthUid;
    console.log('AuthID: ' + uid);
    var object = event.data.val();
    console.log('Whole Object: ', object);

    setTimeout(function() {
    return admin.database.ref('/RoomsOthers/${uid}').set(object);
    }, delayInMilliseconds);

  });
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
Christopher Mills
  • 711
  • 10
  • 28
  • Well in my case I had a function in the form of `const onCreateUser = ....` and then exporting the function like `module.exports = onCreateUser;`. But when I tried `exports.onCreateUser` it worked! – Fotios Tsakiris Apr 15 '20 at 13:44

6 Answers6

31

You didn't actually deploy that function when you ran firebase deploy. If you had successfully deployed it, the name of the function would have appeared in the Firebase CLI output.

Make sure you:

  1. Actually saved the file with the function you're trying to deploy.
  2. The file is in the correct directory. For JavaScript projects, the default is functions/index.js
  3. Are deploying the correct project from the correct directory.
Doug Stevenson
  • 297,357
  • 32
  • 422
  • 441
  • Thanks Doug, item 2 was the helpful one. My index.js was laying outside the functions folder. – Christopher Mills Feb 27 '18 at 21:07
  • also https://stackoverflow.com/questions/43020173/can-not-see-the-firebase-function-deployed – Kevin Potgieter Mar 16 '20 at 08:45
  • In my case I'm using typescript and `firebase deploy` was not building the lib folder again. I guess it was caused by a interface I was importing ouside of the functions folder scope. I delete the `lib` folder and remove this interface and I looks like it's back to normal – Leonardo Rick Aug 30 '20 at 01:21
4

In my case I just had to cd into the functions folder before deploy. Note that you should be getting this in your output:

Cloud functions output including function url and a step about packaging and uploading functions folder

0

For me the problem was in the name of the function. My function name was fooBar but I was using foobar.

firebase deploy --only functions:foobar // Incorrect
firebase deploy --only functions:fooBar // Correct
iDecode
  • 22,623
  • 19
  • 99
  • 186
0

In my case, I was using Typescript and was importing an interface that was outside the function's folder scope. Once I removed that import, it was deployed as I expected.

Lee Taylor
  • 7,761
  • 16
  • 33
  • 49
user7367101
  • 41
  • 1
  • 6
0

I forgot to RETURN the firebase function from inside of a wrapper function.

export const myWrapper = (database: any, url: any) => {
//don't forget the return keyword here!!
  return functions.https.onRequest((req, res) => { }

}

Hope it helps someone down the line.

Louis Sankey
  • 481
  • 8
  • 26
0

For me, the problem was that I was importing some types/interfaces from a level above the functions directory. Therefore, when building, the index.js was in a different location than it was previously.

I had to go to the functiond directory's package.json and update the main to the correct location of index.js within the functions directory.

Then deployed fine.

Jeff Padgett
  • 2,380
  • 22
  • 34