Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Firebase cloud function local code changes are not reflected in emulators

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.

like image 782
Abhimanyu Avatar asked Nov 15 '20 15:11

Abhimanyu


People also ask

Is not open on localhost could not start firestore emulator?

This error is because of the failed quitting from firebase emulator. You already have the process of previous firebase emulator. For a new start, you have to find and stop the previous process.

What is Firebase local emulator suite?

The Firebase Local Emulator Suite is a set of advanced tools for developers looking to build and test apps locally using Cloud Firestore, Realtime Database, Cloud Storage, Authentication, Cloud Functions, Pub/Sub, and Firebase Hosting. It provides a rich user interface to help you get running and prototyping quickly.

What functions are supported by the firebase CLI?

The Firebase CLI includes a Cloud Functions emulator which can emulate the following function types: Background functions triggered from Authentication, Realtime Database, Cloud Firestore, and Cloud Pub/Sub. You can run functions locally to test them before deploying to production.

What version of Firebase do I need to run Cloud Functions?

In order to use the local emulator, your Cloud Functions must depend on: firebase-admin version 8.0.0 or higher. firebase-functions version 3.0.0 or higher.

How do I run functions locally in Firebase?

You can run functions locally to test them before deploying to production. To use the Cloud Functions emulator, first install the Firebase CLI: In order to use the local emulator, your Cloud Functions must depend on: firebase-admin version 8.0.0 or higher. firebase-functions version 3.0.0 or higher.


Video Answer


1 Answers

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.
like image 73
Abhimanyu Avatar answered Oct 14 '22 06:10

Abhimanyu