angulartypescriptfirebaseangularfire

export 'firestore' (imported as 'firebase') was not found in 'firebase' after upgrading to firebase js sdk v8


I have upgraded the firebase JS SDK from v7 to v8.0.0 and I am importing firebase like so.

import * as firebase from 'firebase';

Accessing any of the following causes the error below.

firebase.firestore.FieldValue.serverTimestamp()
firebase.User
firebase.auth.UserCredential

export 'firestore' (imported as 'firebase') was not found in 'firebase' Property 'firestore' does not exist on type 'typeof import("appPath/node_modules/firebase/index")'

I have found a workaround by changing firebase to firebase.default e.g.

firebase.default.firestore.FieldValue.serverTimestamp()

Is this the correct approach to resolve this?

EDIT: I am also using AngularFire in the project. I tried using:

import firebase from 'firebase/app';
import 'firebase/firestore';
export const firestore = firebase.firestore();

But this gave me the following error:

Uncaught FirebaseError: Firebase: No Firebase App '[DEFAULT]' has been created - call Firebase App.initializeApp() (app/no-app).


Solution

  • I ran into the same problem when I updated to Angular 11. I tried the fix to install the firebase-admin library and followed the directions from this thread, but that is not supposed to run in a browser and caused some other issues, so I abandoned that.

    I noticed from the release notes of AngularFire that the latest version does not support older versions of the JS SDK, which is where this function comes from, and so I deleted node_modules, the package-lock.json file, and ran npm cache clean --force and then npm install to run clean. That did nothing, but I felt accomplished.

    And then I ran into this thread which explained my issue and got things to compile by changing the library from

    'import * as firebase from 'firebase/app';

    to

    import firebase from 'firebase/app';

    That removed the "cannot find firestore" error and it compiled correctly. Works with the original code:

    get firebaseTimestamp() { return firebase.firestore.FieldValue.serverTimestamp(); }

    Hope this helps - it was a sticky bug.