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); }); 
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! Commented Apr 15, 2020 at 13:44

6 Answers 6

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.
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Doug, item 2 was the helpful one. My index.js was laying outside the functions folder.
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
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

Comments

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 

Comments

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.

Comments

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.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.