Home > Back-end >  Attempted import error: 'firestore' is not exported from 'firebase/app' (importe
Attempted import error: 'firestore' is not exported from 'firebase/app' (importe

Time:09-26

So I'm having issues with this code. I installed "npm install firebase" I've tried other methods, I feel like it's probably a simple trick to fix this but I kind of needs some help. Anyone know what the issue is?

And I still get this error

Attempted import error: 'firestore' is not exported from 'firebase/app' (imported as 'firebase')


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

var firebaseConfig = {
  apiKey: "AIzaSyBWEyocjrQCjoENYbkKIbVe_2D9bXPe8XA",
  authDomain: "sahm-5a4a0.firebaseapp.com",
  projectId: "sahm-5a4a0",
  storageBucket: "sahm-5a4a0.appspot.com",
  messagingSenderId: "1010829019707",
  appId: "1:1010829019707:web:fb166e26f7f3ac66972a1e",
  measurementId: "G-X27Q0GCH8X"
};

// Initialize Firebase
firebase.initializeApp(firebaseConfig);

const projectStorage = firebase.storage();
const projectFirestore = firebase.firestore();
const timestamp = firebase.firestore.FieldValue.serverTimestamp;

export { projectStorage, projectFirestore, timestamp };

CodePudding user response:

Breaking change: browser fields in package.json files now point to ESM bundles instead of CJS bundles. Users who are using ESM imports must now use the default import instead of a namespace import.

Before 8.0.0

import * as firebase from 'firebase/app'

After 8.0.0

import firebase from 'firebase/app'

Code that uses require('firebase/app') or require('firebase') will still work, but in order to get proper typings (for code completion, for example) users should change these require calls to require('firebase/app').default or require('firebase').default. This is because the SDK now uses typings for the ESM bundle, and the different bundles share one typings file.

So, you will have to use the new ESM bundle default export:

import firebase from "firebase/app"
firebase.initializeApp({ ... })

CodePudding user response:

After a long day of stressing and more research I found out how to fix my issue. So if anyone is having this issue.

npm install firebase@7.16.1
  • Related