'Property 'auth' does not exist on type 'typeof import..." firebase/auth

import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/database';

firebase.initializeApp(firebaseConfig);

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

This is my code but it gives me this error

Property 'auth' does not exist on type 'typeof import("[project path]/node_modules/firebase/app/dist/app/index")'.ts(2339) any



Solution 1:[1]

They updated the imports with v9. The fix is easy, just update to:

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

Here's the relevant section of the docs

Solution 2:[2]

I think this will work, even I faced the same problem Update imports to v9 compat

import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/database';

firebase.initializeApp(firebaseConfig);

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

Before: version 8

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

After: version 9 compat v9 compat packages are API compatible with v8 code

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

Solution 3:[3]

works for me import firebase from 'firebase/compat/app'; import 'firebase/compat/auth'; import 'firebase/compat/firestore';

relevant section of the docs

Solution 4:[4]

For firebase v10 (it can work for other versions) use the following code: (worked for me)

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

firebase.initializeApp(firebaseConfig);

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 misterbastean
Solution 2 Sanket Patil
Solution 3 nh-helperf
Solution 4 Hilati Ashref