Can not see the Firebase function deployed

后端 未结 15 795
失恋的感觉
失恋的感觉 2021-02-02 08:23

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

相关标签:
15条回答
  • 2021-02-02 09:00

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

    firebase deploy
    
    0 讨论(0)
  • 2021-02-02 09:00

    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:

    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

    0 讨论(0)
  • 2021-02-02 09:01

    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.

    0 讨论(0)
  • 2021-02-02 09:01

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

    0 讨论(0)
  • 2021-02-02 09:03

    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.

    0 讨论(0)
  • 2021-02-02 09:06

    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.

    0 讨论(0)
提交回复
热议问题