In my svelte project there is a firebase.js file that manages the firebase services. The file looks like this:
import firebase from "firebase/app"; // rollup bundle issue with ESM import
import "firebase/firestore";
import "firebase/auth";
const firebaseConfig = {
// firebase config
};
console.log(firebase);
firebase.initializeApp(firebaseConfig);
export const auth = firebase.auth();
export const googleProvider = new firebase.auth.GoogleAuthProvider();
export const db = firebase.firestore();
This works perfectly fine, however adding firebase modules seems to cause issues.
e.g. adding import "firebase/analytics"; after the firebase auth an error appears in the browser console
index.esm.js:1301 Uncaught TypeError: Cannot read property 'registerComponent' of undefined
at registerInstallations (index.esm.js:1301)
at index.esm.js:1325
at main.js:6
the index.esm.js file in question is the @firebase/installations file, it appears that the object being passed into registerInstallations(firebase) isn't a firebase app object but is instead an object containing 2 firebase app objects, one named default and one named firebase.
The only way I've found to fix this is by replacing the calls to registerInstallations(firebase) with registerInstallations(firebase.firebase) in multiple places throughout node_modules, which does not seem like a good solution.
Edit: I managed to fix this by rebuilding the entire project, including the rollup config and the package.json. Looking through the git changes there are no differences that should have effected this.