Can not see the Firebase function deployed
Asked Answered
M

20

36

I followed the following steps:

  1. The Firebase CLI (Command Line Interface) requires Node.js and npm, which you can install by following the instructions on https://nodejs.org/

    • Installing Node.js also installs npm
  2. Once you have Node.js and npm installed, install the Firebase CLI via npm:
    npm install -g firebase-tools

    • This installs the globally available firebase command. To update to the latest version, re-run the same command
  3. Initialize your project:
    a. Run firebase login to log in via the browser and authenticate the firebase tool.

    b.Go to your Firebase project directory or create the directory

    c. Run firebase init functions

    • The tool gives you an option to install dependencies with npm. It is safe to decline if you want to manage dependencies in another way.
  4. Select associated firebase project

  5. Select Y to install dependencies with npm

  6. Move to directory setup firebase functions

  7. Edit index.js file with the function you created

  8. Run the firebase use --add to add your Firebase project

  9. Run firebase deploy --only functions to deploy the function

After all this I get the message in the terminal at deploy was completed but in the Firebase console, when i click on Functions tab there are no functions listed!?

Metastasis answered 25/3, 2017 at 18:19 Comment(6)
Did you ever get this resolved? If you post your actual index.js, I might be able to help.Seriate
I'm having the exact same problem, don't yet see a solution in here..Vostok
I had the same issue and found a workaround. It might not be perfect, but is a solution for the moment: you can access the Firebase cloud functions from the Google Cloud ConsoleWheelsman
Hey @Dimitri. Check my answer on this issue.Reverberatory
I had to make sure I ran "npm run-script build" in the directory with all of my source files (multiple) before deploying, firebase seems to deploy from a /lib folder with transpiled source. I later add this npm command to my firebase.json file for "predeploy" commands.Sobel
Also, be sure you are actually saving your file in VS or whatever editor. CTRL+S it before you do firebase deploy -- this got me earlier todayPyrotechnics
S
24

Quick Tip: Make sure you are exporting the function you are trying to deploy in your index.js file. Your firebase project will deploy but Cloud Functions won't be available unless they are exported.

Seriate answered 27/3, 2017 at 21:49 Comment(2)
This worked, using exports = ... or modules.exports = { ... }Sow
Thanks. love that simple stuffWhitechapel
S
10

Make sure you save the file after uncommenting the default function and then use

firebase deploy
Surber answered 12/12, 2017 at 12:37 Comment(2)
The function was exported and index.js existed in functions folder. However, I used the Visual Studio Code to edit index.js and my last changes were not saved. After saving the file and redeploying. It worked fine.Synovitis
"make sure you save the file". I've only been doing this for like 20 years... and yes I forgot to save the file! lolSelfdeceit
Y
6

For Cloud Functions, it is required to add your function to the special exports object (it is a Node's way of making the function accessible outside of the current file) Make sure to have index.js in your functions directory:

enter image description here

Example of a function:

// Import the Firebase SDK for Google Cloud Functions.
const functions = require('firebase-functions');
// Import and initialize the Firebase Admin SDK.
const admin = require('firebase-admin');
admin.initializeApp();



// Your function declaration. Example of a fired function when a user is created in Auth feature.
exports.myFunction = functions.auth.user().onCreate(async (user) => {
// ... your code here.
});

Then for deployment follow these steps:

  • First, if not done, make sure to have firebase-tools installed: $ npm install -g firebase-tools
  • And initialised: $ firebase init

  • For full deployment: $ firebase deploy

  • OR for functions deployment $ firebase deploy --only functions
  • OR to deploy specific functions $ firebase deploy --only functions:function1,functions:function2

A good read with a very useful example: https://codelabs.developers.google.com/codelabs/firebase-cloud-functions/#7

Yore answered 4/3, 2020 at 9:56 Comment(1)
What if you have 2 files instead of 1 index.js? Does this complicate anything? Is there a process needed when going from 1 index.js file to multiple functions files?Bulbar
R
4

I went through the same issue recently, while performing Actions on Google Node.js Client Library Version 1 Migration Guide. to Node.js Client Library V2 (That I highly recommend) It took me a while to figure out what what was happening. At the I couldn't really figure out what the problem was! So here is what I did and it worked for me:

  1. Make sure you have a backup copy of your cloud functions (index.js) and maybe your package.json (Just in case you don't want to remember what packages you previously had installed - Could be annoying sometimes).

  2. Delete the entire functions directory from your project folder.

  3. Re-launch firebase CLI with firebase init and choose Functions

  4. Once your cloud function have been initialized, CD into the functions folder and Redeploy it using firebase deploy --only functions.

  5. If everything goes well 😃, you should now see your function deployed on your firebase dashboard console.

N.B: Google recently released the Node.js Client Library version 2 (v2) in April 16th 2018 with a lot of new features. After April 16th, 2018, new features on Actions on Google will no longer be added to v1 of the client library. If you want to use new features, you must migrate to v2 client library.

In addition, the v1 client library does not support Dialogflow v2. If you need Dialogflow v2 functionality, you’ll also need to migrate to v2 of the client library.

Hope this helps 👍.

Reverberatory answered 17/4, 2018 at 9:51 Comment(1)
this solved my issue. Thank you google for making me waste about 2 hours of my short lifeTrickery
A
4

@Learn2Code I had the exact same issue. Ensure that in your index.js file, you export your function before initializing your app.

Now, go ahead and run firebase deploy from your project directory.

For example:

// Take the text parameter passed to this HTTP endpoint and insert it into the
// Realtime Database under the path /messages/:pushId/original
exports.addMessage = functions.https.onRequest(async (req, res) => {
    // Grab the text parameter.
    const original = req.query.text;
    // Push the new message into the Realtime Database using the Firebase Admin SDK.
    const snapshot = await admin.database().ref('/messages').push({original: original});
    // Redirect with 303 SEE OTHER to the URL of the pushed object in the Firebase console.
    res.redirect(303, snapshot.ref.toString());
  });

const admin = require('firebase-admin');
admin.initializeApp();
Arrogate answered 1/11, 2019 at 1:51 Comment(1)
+1 for const admin = require('firebase-admin'); admin.initializeApp(); Reincarnation
R
3

In step 7, you have to uncomment the sample function in there and save the file. Then, in the output of the deploy command, you will be given a url for the created helloWorld function.

Rickettsia answered 25/3, 2017 at 21:34 Comment(0)
K
3

I had exactly the same problem and I solved it by making sure the index.js file containing all my functions was saved on the "functions" folder inside the project folder. I am using vs code so I just clicked on file/save as and selected the correct folder.

Kiker answered 18/2, 2018 at 23:22 Comment(0)
U
2

Make sure you're running at least version 3.5.0 of firebase-tools. To check which version you have, run:

firebase --version

If you're running the default setup, you can update firebase-tools using:

npm install -g firebase-tools
Unlovely answered 7/4, 2017 at 16:52 Comment(0)
K
2

Had the same situation. The problem was that when I was doing

$ firebase deploy --only "myFunction" 

That filter name: myFunction, was not exactly the same as the name of the function I was trying to deploy. Silly mistake but took me a day to realize...

Kimmy answered 18/12, 2018 at 13:20 Comment(0)
T
1

To clarify one issue - it appears as though your index.js file inside the functions folder must export functions created within the same file (similar to what Fran had said).

It seems trying to organize your files into subfolders will not work properly with Firebase functions - same rules apply for using firebase serve to test locally (must create codeinside functions/index.js).

Hope this helps someone!

Thierry answered 29/4, 2018 at 6:49 Comment(0)
E
1

You probably deleted these default lines and forgot to export:

const functions = require("firebase-functions");

exports.helloWorld = functions.https.onRequest((request, response) => 
{
    functions.logger.info("Hello logs!", {structuredData: true});
    response.send("Hello from Firebase!");
});
Euh answered 7/5, 2023 at 12:49 Comment(1)
You were such a blessing, I had hours trying to figure out the problem, turns out I replaced the default index.ts code and that was the problem, I left the default lines as you said and problem solved, thank you!Sevenup
A
1

If you are using Typescript and you also have a client app in the same repo, you might made the same mistake as I did:

If you accidentally import something from the frontend client folder, the the Typescript will compile the new files differently, to include the client folder in the function lib folder.

So to fix that you'll need to remove the import from client folder.

Achaean answered 3/3 at 6:58 Comment(0)
A
0

1) Make sure you are exporting the function you are trying to deploy in your index.js file.

2) Write 'use-strict' at the top of your file (index.js) then use console to deploy your function

Asthenic answered 3/6, 2018 at 11:4 Comment(0)
S
0

Check your "default project" at firebase init. Select one with similar name was my mistake. ;)

Saviour answered 13/8, 2018 at 9:42 Comment(0)
A
0

Use firebase projects:list and firebase use <project> to make sure the Firebase CLI's "current project" is set correctly regardless of what folder you're in.

Example:

> firebase projects:list
  ✔ Preparing the list of your Firebase projects
  ┌──────────────────────┬─────────────────────┬──────────────────────┐
  │ Project Display Name │ Project ID          │ Resource Location ID │
  ├──────────────────────┼─────────────────────┼──────────────────────┤
  │ alpha                │ alpha     (current) │ [Not specified]      │
  ├──────────────────────┼─────────────────────┼──────────────────────┤
  │ beta                 │ beta                │ [Not specified]      │
  └──────────────────────┴─────────────────────┴──────────────────────┘

  2 project(s) total.

> firebase use beta
  Now using project beta
Attributive answered 9/10, 2019 at 17:28 Comment(0)
N
0

I had this error as well. I had copied a working function running on Google Cloud Functions from a previous project and could not figure out why it would not show up once deployed.

I needed to wrap my function in functions.https.onRequest(), which is not required on normal cloud functions.

Nannienanning answered 1/5, 2020 at 21:0 Comment(0)
A
0

Had the same issue.

In my case solved by using firebase deploy wihtout any --only, which revealed better error messaging and I had to setup billing in Cloud Console for the project. The setup routine can be triggered by selecting Could Functions in the Console.

I had another issue in which the Service Account was missing from the Project, so I setup a fresh project through the Console first and then added this to Firebase.

Assured answered 4/11, 2020 at 16:35 Comment(0)
H
0

Make sure you init firebase on step back from your firebase functions. and also firebase functions name must be functions.

It works for me

Housekeeping answered 15/5, 2022 at 8:20 Comment(0)
U
0

One dumb gotcha I just ran into, I was running "firebase deploy" from the top level folder (one above the /functions sub-folder), and it deployed "successfully" but I never saw it in Firebase itself. It wasn't until I cd'd into /functions and re-ran firebase deploy that the full deployment actually worked.

Ursine answered 26/10, 2022 at 3:9 Comment(0)
N
0

Make sure you're running the command from your functions folder.

C:\yourProject\functions> run the command here (in your case firebase deploy --only functions

Did the trick for me :)

Nonchalant answered 12/4, 2023 at 15:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.