I'm using firebase realtime database and trying to use the Auth method firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.auth is not a function

I tried some resolutions and suggestions that I saw in Stackoverflow, however still getting the message

import firebase from 'firebase/compat/app';

import 'firebase/auth';
import 'firebase/database';



// Your web app's Firebase configuration
const firebaseConfig = {
  apiKey: process.env.REACT_APP_API_KEY,
  authDomain: process.env.REACT_APP_AUTH_DOMAIN,
  databaseURL: process.env.REACT_APP_DATABASE_URL,
  projectId: process.env.REACT_APP_PROJECT_ID,
  storageBucket: process.env.REACT_APP_STORAGE_BUCKET,
  messagingSenderId: process.env.REACT_APP_MESSAGING_SENDER_ID,
  appId: process.env.REACT_APP_APP_ID
};

// Initialize Firebase
//const app = initializeApp(firebaseConfig);
firebase.initializeApp(firebaseConfig);

export const auth = firebase.auth();
export const database = firebase.database();

Solution 1:

You'll have to import compat versions of every Firebase service (at least whichever will use the namespaced syntax):

import firebase from 'firebase/compat/app';

import 'firebase/compat/auth';
import 'firebase/compat/database';
// add compat in these imports

firebase.initializeApp(firebaseConfig);

// Namespaced syntax requires compat version
export const auth = firebase.auth();
export const database = firebase.database();