Firebase.auth().useEmulator is not a function

Tags: , , ,



I currently have a project set up through VueCLI and firebase-tools and can’t seem to be able to attach the Firebase Auth emulator to my project locally.

My Firebase Set-up file:

import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
import 'firebase/storage';

const configOptions = {
    apiKey: process.env.VUE_APP_FIREBASE_API_KEY,
    authDomain: process.env.VUE_APP_FIREBASE_AUTH_DOMAIN,
    databaseURL: process.env.VUE_APP_FIREBASE_DB_URL,
    projectId: process.env.VUE_APP_FIREBASE_PROJECT_ID,
    storageBucket: process.env.VUE_APP_FIREBASE_STORAGE_BUCKET,
    messagingSenderId: process.env.VUE_APP_FIREBASE_MESSAGING_SENDER_ID,
    appId: process.env.VUE_APP_FIREBASE_APP_ID,
    measurementId: process.env.VUE_APP_FIREBASE_MEASUREMENT_ID
};

firebase.initializeApp(configOptions);

if (process.env.NODE_ENV === "development"){
    firebase.firestore().settings({ host: 'localhost:8080', ssl: false });
    firebase.auth().useEmulator('http://localhost:9099/');
}

export const firebaseauth = firebase.auth();
export const firestore = firebase.firestore();
export const firebasestorage = firebase.storage();
export default firebase;

My .env.development file

VUE_APP_I18N_LOCALE=en
VUE_APP_I18N_FALLBACK_LOCALE=en

VUE_APP_FIREBASE_API_KEY="xx"
VUE_APP_FIREBASE_AUTH_DOMAIN="localhost:9099"
VUE_APP_FIREBASE_DB_URL="http://localhost:4000"
VUE_APP_FIREBASE_PROJECT_ID="xx"
VUE_APP_FIREBASE_STORAGE_BUCKET="xx"
VUE_APP_FIREBASE_MESSAGING_SENDER_ID="xx"
VUE_APP_FIREBASE_APP_ID="xx"
VUE_APP_FIREBASE_MEASUREMENT_ID="xx"

When navigating to localhost:5000 (emulated hosting), I get the error:

Uncaught TypeError: firebase_app__WEBPACK_IMPORTED_MODULE_0___default.a.auth(…).useEmulator is not a function

useEmulator comes directly from Google’s Firebase Documentation so I’m unsure what I’m doing incorrectly.

Answer

It may be that you’re still using a firebase version older than version 8.0.0, in that case the method you’d want to call is the .useFunctionsEmulator method (deprecated since v8.0.0):

firebase.functions().useFunctionsEmulator('http://localhost:5001');


Source: stackoverflow