I recently upgraded Firebase to 10.12.4 and now have this error which isn’t allowing me to compile.
import firebase from 'firebase/compat/app';
import "firebase/compat/auth";
import "firebase/compat/database";
import "firebase/compat/firestore";
import "firebase/compat/storage";
const firebaseConfig = {
apiKey: "xxx",
authDomain: "xxx",
databaseURL: "xxx",
projectId: "xxx",
storageBucket: "xxx",
messagingSenderId: "xxx",
appId: "xxx",
measurementId: "xxx",
};
firebase.initializeApp(firebaseConfig);
firebase.firestore().settings({ experimentalForceLongPolling: false, cacheSizeBytes: firebase.firestore.CACHE_SIZE_UNLIMITED, merge: true });
export const storage = firebase.storage();
export default firebase;
This has worked with no problems in the past – but am wondering why it now throwing this error, and how to fix it?
2
Answers
Since Firebase v9, they’ve moved all their packages to a Modular structure. You should import the necessary methods to from the right modules. According to the documentation, I can see that you’re doing the wrong imports.
To initialize your Firebase app you can do the following:
Upon checking, I can also see since you’re using
compat
exports you can initialize your app as following too:Given that, I suppose you’re using the official Firebase library – if you’re just not sure you can install the Firebase dependencies using the
Check the full documentation here.
Hope this helps.
The new firebase documentations suggests upgrading from namespace API to modular API.
You can check the documentation on firebase docs.
Be sure to add credentials in the environment file.
And If you still need to use the compat version, I didn’t found firebase/compat/app on npmjs available packages. Try using firebase/app-compat, firebase/firestore-compat, firebase/auth-compat, etc.