Search code examples
javascriptgoogle-cloud-firestorefirebase-cli

Firebase deploy functions doesn't deploy


I'm learning firebase for my new project, I need to deploy 1 function and when I run firebase deploy --only functions:updateDatabase I get this output in the terminal:

deploying functions
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
+  functions: required API cloudfunctions.googleapis.com is enabled
+  functions: required API cloudbuild.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged functions (75 KB) for uploading
+  functions: functions folder uploaded successfully
i  functions: cleaning up build files...

+  Deploy complete!

but the function is not deployed. I tried to reinstall node-modules, npm i. I have access to the project itself on the firebase, but can't figure out why tihs function is not deploying and there is no error message. Any help and advise is greatly appreciated.


Solution

  • Based on the question above, The possible root cause for this issue is you didn't export the functions properly. Properly export the function and deploy. See example code below.

    const functions = require("firebase-functions");
    
    // Create and Deploy Your First Cloud Functions
    // https://firebase.google.com/docs/functions/write-firebase-functions
    
    exports.helloWorld = functions.https.onRequest((request, response) => {
      functions.logger.info("Hello logs!", {structuredData: true});
      response.send("Hello from Firebase!");
    });
    
    firebase deploy --only functions:helloWorld
    

    This would deploy because the function is exported properly.

    However, by deploying a function like below:

    const functions = require("firebase-functions");
    
    // Create and Deploy Your First Cloud Functions
    // https://firebase.google.com/docs/functions/write-firebase-functions
    
    function helloWorld() {
      functions.logger.info("Hello logs!", {structuredData: true});
      response.send("Hello from Firebase!");
    };
    

    will result to:

    i  deploying functions
    i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
    i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
    ✔  functions: required API cloudfunctions.googleapis.com is enabled
    ✔  functions: required API cloudbuild.googleapis.com is enabled
    i  functions: cleaning up build files...
    
    ✔  Deploy complete!
    

    Thus, the function is not properly deployed.

    You may check Get started: write, test, and deploy your first functions for more information.