firebase-functions:
0.5.9
firebase-tools:
3.9.1
firebase-admin:
4.2.1
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.
firebase deploy --only functions
Yes, but only the first time.
After making changes to the functions, they should actually redeploy.
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!
Did you change the file name at all? Or add anything new to firebase.json?
I deleted firebase.json and started over. Then it worked.
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 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 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.
@laurenzlong It's possible I'm just being silly and doing something dumb ha... any thoughts?
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 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
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 => {
I renamed my function, then when doing "firebase deploy" I selected "yes" to delete the old one. That got the changes applied
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",
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:
functions folderlib folder (this helped me to realize of the old code and the new one)yarn buildpackage.json -> "main" to the right entrey point, in my case "main": "lib/src/index.js"firebase deploy --only functionsThank you again for pointing me the solution, it will take ages to figure out.
then everything was updated
Most helpful comment
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",