[Vuejs]-Vue + Firebase: Functions useEmulator() ignored

2👍

This line:

firebase.functions()

is functionally equivalent to:

firebase.app().functions('us-central1')

In your current code, you connect functions that don’t specify a region to the emulator. Because you specify the region as europe-west2 when using it, you need to connect the europe-west2 functions to the emulator. You can do this by changing this line:

firebase.functions().useEmulator('localhost', 5001);

to use the correct region:

firebase.app().functions('europe-west2').useEmulator('localhost', 5001)

Additional Note: While firebase.functions() and firebase.app().functions() return the same instance of a Functions object (connected to the us-central1 region), firebase.app().functions('us-central1') (where you pass in the region) returns a different instance of Functions. You would need to connect each instance that you use to the emulator.

1👍

Here’s your code as I make sure that useEmulator() is configured properly with Cloud Functions for Firebase Emulator. Feel free to try it:

import firebase from 'firebase/app';
import 'firebase/functions';

const firebaseConfig = {
 // Your config
};

const app = firebase.initializeApp(firebaseConfig);
const functions = app.functions('europe-west2');

functions.useEmulator('localhost', 5001);

const func = {
  botcheck: functions.httpsCallable('validateRecaptcha'),
};

export { func };

Leave a comment