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).
To solve the “export 'default' (imported as 'firebase') was not found in 'firebase/app'” error, simply upgrade imports to v9 compatibility, according to Firebase docs.
To Solve Attempted import error: 'firebase/app' does not contain a default export (imported as 'firebase') Error If You are using Version 9 then don't forget that things changed a bit for importing firebase Now there is a “compatibility” option so can use the /compat folder in your imports.
For those getting similar error on version 9 Firebase, make sure to change your path to:
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
...
instead of:
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
...
Taken from firebase doc
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.
Use
import firebase from "firebase/app";
import "firebase/database";
instead of
'import * as firebase from 'firebase/app';
This may help
Hi here the form that i use
import { AngularFireAuth } from '@angular/fire/compat/auth';
import firebase from 'firebase/compat/app';
Hope it help's !
Before: version 8
import firebase from 'firebase/app';
import 'firebase/auth';
import 'firebase/firestore';
CHANGE TO ====>
After: version 9 compact
import firebase from 'firebase/compat/app';
import 'firebase/compat/auth';
import 'firebase/compat/firestore';
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With