Coder Social home page Coder Social logo

Comments (15)

Enricopv avatar Enricopv commented on June 12, 2024 5

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",

from firebase-functions.

pikilon avatar pikilon commented on June 12, 2024 5

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

from firebase-functions.

laurenzlong avatar laurenzlong commented on June 12, 2024 2

Thanks for the link! If you follow the conversation, in googleapis/google-auth-library-nodejs#320 (comment), @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 => {

from firebase-functions.

laurenzlong avatar laurenzlong commented on June 12, 2024 1

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

from firebase-functions.

laurenzlong avatar laurenzlong commented on June 12, 2024

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

from firebase-functions.

alexbjorlig avatar alexbjorlig commented on June 12, 2024

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

from firebase-functions.

paujur avatar paujur commented on June 12, 2024

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...

from firebase-functions.

laurenzlong avatar laurenzlong commented on June 12, 2024

@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)

from firebase-functions.

paujur avatar paujur commented on June 12, 2024

@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.

from firebase-functions.

paujur avatar paujur commented on June 12, 2024

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

from firebase-functions.

paujur avatar paujur commented on June 12, 2024

@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: googleapis/google-auth-library-nodejs#320

from firebase-functions.

apbeers avatar apbeers commented on June 12, 2024

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

from firebase-functions.

kbottner avatar kbottner commented on June 12, 2024

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.

from firebase-functions.

PeterF2170 avatar PeterF2170 commented on June 12, 2024

@Enricopv thank you, this issue is still a thing

from firebase-functions.

Biokimist avatar Biokimist commented on June 12, 2024

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.

from firebase-functions.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.