Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

What am I doing wrong with this firebase snippet I found multiple times around the web?

enter image description here

Property 'auth' does not exist on type 'typeof import("/home/nuhutuh25/Desktop/ignition/registry/node_modules/firebase/app/dist/app/index")'.ts(2339)

I did install firebase as a dependency and also saw someone successfully writing const auth=app.auth() but that does not work either because type FirebaseApp has no attribute auth.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

I am using typescript.

>Solution :

It seems you have the new Firebase Modular SDK installed (V9.0.0+) which has a new syntax unlike the older name-spaced one. If you want to keep using existing syntax you can switch to compat version:

import firebase from "firebase/compat/app"
import "firebase/compat/auth"

I would recommend upgrading to Modular SDK because the compat libraries are a temporary solution that will be removed completely in a future major SDK version.

Try refactoring your code as shown below:

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";

const app = initializeApp({...firebaseConfig});

export const auth = getAuth(app);
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading