1
votes

I've been following the codelabs tutorial here to deploy my first functions to firebase. I've made it to step 8 of the tutorial ("Welcome new users").

The deploy looks successful when I run firebase deploy --only functions from within the functions subdirectory:

Marks-MacBook-Air-3:functions mf$ firebase deploy --only functions

=== Deploying to 'friendlychat-21221'...

i deploying functions Running command: npm --prefix "$RESOURCE_DIR" run lint

functions@ lint /Users/mf/Desktop/friendlychat-web/cloud-functions-start/functions eslint .

✔ functions: Finished running predeploy script. i functions: ensuring necessary APIs are enabled... ✔ functions: all necessary APIs are enabled i functions: preparing functions directory for uploading...

✔ Deploy complete!

But looking at my firebase dashboard, it doesn't look like they deployed after all: enter image description here

I'm not even sure where to begin troubleshooting, since the logs in the cloud functions tab is empty.

Has anyone encountered this before and/or have a good troubleshooting strategy?

Update 1:15 PM Friday 25 May, 2018: This is my index.js file in the functions subdirectory:

const functions = require('firebase-functions');
const admin = require('firebase-admin');
admin.initializeApp();

// TODO(DEVELOPER): Write the addWelcomeMessages Function here.
// Adds a message that welcomes new users into the chat.
exports.addWelcomeMessages = functions.auth.user().onCreate(user => {
  console.log('A new user signed in for the first time.');
  const fullName = user.displayName || 'Anonymous';

  // Saves the new welcome message into the database
  // which then displays it in the FriendlyChat clients.
  return admin.database().ref('messages').push({
    name: 'Firebase Bot',
    photoUrl: '/images/firebase-logo.png', // Firebase logo
    text: `${fullName} signed in for the first time! Welcome!`, // Using back-ticks.
  }).then(() => {
    console.log('Welcome message written to database.');
  });
});
// TODO(DEVELOPER): Write the blurOffensiveImages Function here.

// TODO(DEVELOPER): Write the sendNotifications Function here.

Here are the contents of the functions subdirectory:

enter image description here

2
Make sure you are exporting the function you are trying to deploy in your index.js file.Fateme Fazli
@fatemefazli I added index.js above. I believe that I am exporting. Can you confirm that the above is what you meant?Atticus29
i mean making sure the index.js file containing all your functions are saved on the "functions" folder inside the project folder.Fateme Fazli
@fatemefazli gotcha. Yup. Index.js is in there (updated)Atticus29
emmm it seems OK, consider that Deploying functions extremely slow.Fateme Fazli

2 Answers

1
votes

I ended up getting it to work after changing two things (and I'm not sure which one fixed this issue; perhaps both):

  1. run npm install from inside the functions directory before you deploy the functions (which should be done in the parent directory).
  2. Be aware that when you run firebase init and cause an overwrite of your index.js file, that file may just have a commented out 'helloWorld' function...
0
votes

Try Firebase list to list all the project that you have in firebase under the signed in account and see if the project you are deploying to shows up. In the case where it doesn't show try this:

  • firebase logout && firebase login
  • firebase list
  • firebase use <alias_or_project_id>
  • firebase deploy --only functions or firebase deploy --only functions:<function_name>

Hope this helps!