Can not see the Firebase function deployed

2020-05-21 11:21发布

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

14条回答
看我几分像从前
2楼-- · 2020-05-21 11:57

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

查看更多
唯我独甜
3楼-- · 2020-05-21 11:58

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

firebase deploy
查看更多
家丑人穷心不美
4楼-- · 2020-05-21 11:58

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.

查看更多
啃猪蹄的小仙女
5楼-- · 2020-05-21 12:00

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!

查看更多
戒情不戒烟
6楼-- · 2020-05-21 12:01

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
查看更多
forever°为你锁心
7楼-- · 2020-05-21 12:02

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.

查看更多
登录 后发表回答