12

I am trying to develop API for my apps using Firebase cloud functions.
Following this site to use the firebase emulator suite for development and testing locally.

Issue: The changes are not reflected in the locally emulated functions.

Steps:

  1. index.js:

    exports.test = functions.https.onRequest(async (request, response) => {
       response.status(200).send("First");
    });
    
  2. Successfully deployed the test method.

    firebase deploy --only functions:test
    
  3. In Postman made the following GET request.

     https://us-central1-<project-name>.cloudfunctions.net/test
    

    Result: First
    Status: 200 OK

  4. Started the emulators:

    firebase emulators:start --only functions
    
  5. In Postman made the following GET request.

     http://localhost:5001/<project-name>/us-central1/indexTest
    

    Result: First
    Status: 200 OK
    Same as the actual deployed function.

  6. Changed the function code to:

    exports.test = functions.https.onRequest(async (request, response) => {
        response.status(200).send("Second");
    });
    
  7. Getting the same result as before when hitting the emulated function in localhost. The changes are not reflected.

Also, tried stopping the emulator and starting it again. No luck.

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
Abhimanyu
  • 11,351
  • 7
  • 51
  • 121
  • To be clear, are you expecting the emulator to reload the code dynamically after you change it? Did you save the file? If you think the emulator is not working correctly, you should file a bug on GitHub. https://github.com/firebase/firebase-tools – Doug Stevenson Nov 15 '20 at 16:51
  • @DougStevenson, I have saved the file. Dynamically reload the code changes, load the code changes after restarting the emulator anything is fine. It is not loading the changes in any way until the code is deployed to production, which makes local emulators pointless. – Abhimanyu Nov 15 '20 at 17:15
  • @DougStevenson, I have filed a bug as suggested: https://github.com/firebase/firebase-tools/issues/2823. – Abhimanyu Nov 15 '20 at 17:27

1 Answers1

17

I had raised an issue in the firebase-tools repo as suggested by DougStevenson. Got the issue resolved with Sam Stern's support.

Posting the solution here for anyone else who gets stuck in the same issue.

Solution:

  1. After every change to the ts files, run "npm run build" to compile the code again.
  2. Change "build": "tsc" to "build": "tsc -w" in package.json if you want to auto-compile after every change.
Abhimanyu
  • 11,351
  • 7
  • 51
  • 121