问题
I followed the following steps:
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
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
Initialize your project:
a. Runfirebase 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.
Select associated firebase project
Select
Y
to install dependencies with npmMove to directory setup firebase functions
Edit
index.js
file with the function you createdRun the
firebase use --add
to add your Firebase projectRun
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:
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
回答5:
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.
回答6:
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:
Make sure you have a backup copy of your cloud functions (
index.js
) and maybe yourpackage.json
(Just in case you don't want to remember what packages you previously had installed - Could be annoying sometimes).Delete the entire functions directory from your project folder.
Re-launch firebase CLI with
firebase init
and choose FunctionsOnce your cloud function have been initialized, CD into the functions folder and Redeploy it using
firebase deploy --only functions
.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 👍.
回答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:
@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();
回答9:
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!
回答10:
1) Make sure you are exporting the function you are trying to deploy in your index.js file.
2) Write 'use-strict' at the top of your file (index.js) then use console to deploy your function
回答11:
Check your "default project" at firebase init. Select one with similar name was my mistake. ;)
回答12:
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
回答13:
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
来源:https://stackoverflow.com/questions/43020173/can-not-see-the-firebase-function-deployed