Typescript error on firebase.initializeApp(config)

Versions:
“firebase”: “^8.2.3”,
“firebase-admin”: “^9.4.2”,
“firebase-functions”: “^3.13.1”,

devDependencies:
“@types/firebase”: “^3.2.1”,
“typescript”: “^4.1.3”

Problem:
Type error on using firebase.initializeApp(firebaseConfig)
Error message: Property 'initializeApp' does not exist on type 'typeof import("/projectTest/node_modules/firebase/index")'

Code:

import * as firebase from 'firebase/app'
import 'firebase/analytics'
import 'firebase/firestore'

const firebaseConfig = {
  apiKey: _apiKey_,
  authDomain: _authDomain_,
  databaseURL: _databaseURL_,
  projectId: _projectId_,
  storageBucket: _storageBucket_,
  messagingSenderId: _messagingSenderId_,
  appId: _appId_,
  measurementId: _measurementId_,
}

// Initialize Firebase
try {
  firebase.initializeApp(firebaseConfig) //error occurs here
} catch (err) {
  if (!/already exists/.test(err.message)) {
    console.error('Firebase initialization error', err.stack)
  }
}

export default firebase

1 possible answer(s) on “Typescript error on firebase.initializeApp(config)