firebase-functions icon indicating copy to clipboard operation
firebase-functions copied to clipboard

Changes to functions are not deployed

Open alexbjorlig opened this issue 9 years ago • 15 comments

Version info

firebase-functions: 0.5.9 firebase-tools: 3.9.1 firebase-admin: 4.2.1

Test case

Deploying functions the first time works. But the second time, I get the "Deploy complete" message quickly, and the changes to the existing functions are not deployed.

Steps to reproduce

firebase deploy --only functions

Were you able to successfully deploy your functions?

Yes, but only the first time.

Expected behavior

After making changes to the functions, they should actually redeploy.

Actual behavior

I recieve the message "Deploy complete!", but nothing happens. Here is the output:

=== Deploying to 'amentocph-test'...

i deploying i starting release process (may take several minutes)...

✔ Deploy complete!

alexbjorlig avatar Jul 30 '17 07:07 alexbjorlig

Did you change the file name at all? Or add anything new to firebase.json?

laurenzlong avatar Aug 01 '17 00:08 laurenzlong

I deleted firebase.json and started over. Then it worked.

alexbjorlig avatar Aug 04 '17 15:08 alexbjorlig

I'm having the same issue... I've been successfully deploying my functions and yet no changes are taking effect. Not sure what to do...

paujur avatar Jun 22 '18 02:06 paujur

@paujur Are you using TypeScript? As well, do you actually get success message saying which functions were updated? If the Firebase CLI was unable to find any functions, it will also print a successfully deployed message, but with no mention of specific functions (so essentially it successfully deployed, but it deployed nothing)

laurenzlong avatar Jun 22 '18 18:06 laurenzlong

@laurenzlong Yes, I'm using Typescript. So I just went through the whole process again. First tested as is, it failed as it should have (since it wasn't updated yet). Then ran the deploy again, everything was successful, but the function did not deploy changes. Here are the console outputs: https://cl.ly/22370W3o1H0k & https://cl.ly/2B3n3p3Q1332 -> same things were logged to the console, even though I deleted all console logs (among other changes). Also, for some odd reason the last error was logged multiple times. But that's a fluke.

Here you can see that the sendMessage function was deployed successfully: https://cl.ly/0J2i453N0O3R

And here is my sendMessage function:

` export const sendMessage = functions.https.onCall((data, context ) => { // Message text passed from the client. const message = data.message; const text = message.text; const phoneNumber = data.phoneNumber; const companyID = data.companyID; const teamID = data.teamID; let accountSid: string; let authToken: string; // TODO: maybe figure out the type here... let client: any; admin.firestore().collection('companies').doc(companyID) .get().then( companyDoc => { const companyData = companyDoc.data(); accountSid = companyData.twilioSid; authToken = companyData.twilioAuthToken; client = new twilio(accountSid, authToken); admin.firestore().collection('companies').doc(companyID).collection('teams').doc(teamID) .get().then( teamDoc => { const teamData = teamDoc.data(); const twilioNumber = teamData.twilioPhoneNumber; if ( !validE164(phoneNumber) ) { throw new Error('number must be E164 format!') } const textMessage = { body: text, to: phoneNumber, // Text to this number from: twilioNumber // From a valid Twilio number };

      client.messages.create(textMessage).then( response => {
          // console.log(response.sid, 'success');
          return { 'success': response };
        }
      ).catch(err => {
        // console.log(err);
        return {'error': err };
      })
    });
  });

  /// Validate E164 format
  function validE164(num) {
    return /^\+?[1-9]\d{1,14}$/.test(num)
  }

} ); `

I even waited 15 minutes to make sure everything is deployed properly. Sometimes, when I try to run the function too soon after deployment I get this error:

Error: Unexpected error while acquiring application default credentials: Could not load the default credentials. Browse to https://developers.google.com/accounts/docs/application-default-credentials for more information. at GoogleAuth.<anonymous> (/user_code/node_modules/firebase-admin/node_modules/google-auth-library/build/src/auth/googleauth.js:248:31) at step (/user_code/node_modules/firebase-admin/node_modules/google-auth-library/build/src/auth/googleauth.js:47:23) at Object.next (/user_code/node_modules/firebase-admin/node_modules/google-auth-library/build/src/auth/googleauth.js:28:53) at fulfilled (/user_code/node_modules/firebase-admin/node_modules/google-auth-library/build/src/auth/googleauth.js:19:58) at process._tickDomainCallback (internal/process/next_tick.js:135:7)

Any ideas? Was ripping my hair out for a while not realizing that it wasn't deploying correctly to begin with haha.

paujur avatar Jun 23 '18 00:06 paujur

@laurenzlong It's possible I'm just being silly and doing something dumb ha... any thoughts?

paujur avatar Jun 26 '18 19:06 paujur

Could you try running npm run build in your functions folder prior to running firebase deploy to ensure that your source code is compiled?

laurenzlong avatar Jun 26 '18 21:06 laurenzlong

@laurenzlong Yes, it builds correctly. But I think I may have an idea of what's going on... It seems like every time I deploy the function and then go to use it, I get an error about the credentials missing. Which shouldn't be the case because the default credentials should be pulled I believe. So I'm thinking that somehow the credentials either aren't being pulled, so either the deployment never really succeeds even though it says it does, or when triggering the function, the credentials aren't found so it falls back to the cached function.

It seems like this bug has been submitted already, but not resolved: https://github.com/google/google-auth-library-nodejs/issues/320

paujur avatar Jun 28 '18 02:06 paujur

Thanks for the link! If you follow the conversation, in https://github.com/google/google-auth-library-nodejs/issues/320#issuecomment-377665587, @jkoelker has found that this error message is caused by unreturned promises. In that case it was the spanner library, but in your case I see at least 2 lines where you are missing a return at the beginning of the statement:

admin.firestore().collection('companies').doc(companyID)
 client.messages.create(textMessage).then( response => {

laurenzlong avatar Jul 02 '18 22:07 laurenzlong

I renamed my function, then when doing "firebase deploy" I selected "yes" to delete the old one. That got the changes applied

apbeers avatar Feb 07 '19 18:02 apbeers

Using TypeScript.

My issue was that the "main" field in package.json got out of sync with how my project developed. Because of that, firebase kept deploying my old code and not uploading the new code generated from "tsc". I wont get into the nitty gritty out of my project, but to others I would advise to make sure that your "main" field in your package.json actually points to the correct index.js of your /lib folder.

"main": "lib/wherever/the/correct//index.js/is/for/you",

Enricopv avatar Jun 12 '19 21:06 Enricopv

Using TypeScript.

My issue was that the "main" field in package.json got out of sync with how my project developed. Because of that, firebase kept deploying my old code and not uploading the new code generated from "tsc". I wont get into the nitty gritty out of my project, but to others I would advise to make sure that your "main" field in your package.json actually points to the correct index.js of your /lib folder.

"main": "lib/wherever/the/correct//index.js/is/for/you",

Ok, this was the solution for me, Thanks! this are the steps I did to make this work:

  • Everything inside functions folder
  • deleted lib folder (this helped me to realize of the old code and the new one)
  • yarn build
  • Point package.json -> "main" to the right entrey point, in my case "main": "lib/src/index.js"
  • firebase deploy --only functions

Thank you again for pointing me the solution, it will take ages to figure out. then everything was updated

pikilon avatar Dec 08 '19 11:12 pikilon

I had the same problem. I know exactly how my package.json file got out of sync with my project. I added a second root folder to my project so it stopped building my single root folder directly into lib/ and instead started building it in the subfolder. Once I updated package.json with the new path to index.js everything was working once again.

kbottner avatar May 28 '21 02:05 kbottner

@Enricopv thank you, this issue is still a thing

PeterF2170 avatar May 18 '22 06:05 PeterF2170

It still a thing. A way to make the changed applied is to run: 'npm start' in the functions folder. It start compilation in watch mode, then if i deploy the last update are deployed. I don't know where, but it fell like a configuration file miss the instruction to compile before deploying.

Biokimist avatar Oct 19 '23 16:10 Biokimist