Firebase function deploying, but not showing up in console
Asked Answered
H

6

17

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

  });
Henna answered 27/2, 2018 at 20:24 Comment(1)
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!Rifling
C
32

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.
Cons answered 27/2, 2018 at 20:27 Comment(3)
Thanks Doug, item 2 was the helpful one. My index.js was laying outside the functions folder.Henna
also #43020673Freak
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 normalIncrease
M
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

Mccahill answered 19/5, 2019 at 10:21 Comment(0)
I
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
Interrex answered 3/8, 2021 at 6:52 Comment(0)
V
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.

Veronaveronese answered 20/6, 2022 at 16:27 Comment(0)
C
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.

Cloudberry answered 23/11, 2022 at 20:46 Comment(0)
D
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.

Digest answered 7/4, 2023 at 17:48 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.