Can not see the Firebase function deployed

2020-05-21 11:56发布

问题:

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

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



回答2:

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

firebase deploy


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



回答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();


回答5:

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


回答6:

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.



回答7:

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



回答8:

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