Can not see the Firebase function deployed

22,056

Solution 1

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.

Solution 2

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

firebase deploy

Solution 3

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

Solution 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 👍.

Solution 5

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.

Share:
22,056
Learn2Code
Author by

Learn2Code

Learning iOS programming with Firebase backend, then want to also learn Android to complete an app come Fall prior to the football season...

Updated on April 14, 2021

Comments

  • Learn2Code
    Learn2Code about 3 years

    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!?