TypeError: _firebase__WEBPACK_IMPORTED_MODULE_2__.default.collection is not a function #36521
-
|
React is telling me there's an error in this part of my code. At first I had different errors but they were Firebase syntax related and I promptly fixed them but now I don't have a clue on what this error means. My code works on localhost for a split second (I see my application) and then the error appears. whenever I tried to import import { auth } from './firebase';
import { getFirestore } from 'firebase/firestore';Here is my firebase.js import firebase from "firebase/app"
import "firebase/auth"
import "firebase/firestore";
const app = firebase.initializeApp({
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.REACT_APP_FIREBASE_APP_ID
})
export const auth = app.auth()
export default app |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
|
The problem is with your import firebase from "firebase/app"
import "firebase/auth"
import "firebase/firestore";
const firebaseApp = firebase.initializeApp({
apiKey: process.env.REACT_APP_FIREBASE_API_KEY,
authDomain: process.env.REACT_APP_FIREBASE_AUTH_DOMAIN,
databaseURL: process.env.REACT_APP_FIREBASE_DATABASE_URL,
projectId: process.env.REACT_APP_FIREBASE_PROJECT_ID,
storageBucket: process.env.REACT_APP_FIREBASE_STORAGE_BUCKET,
messagingSenderId: process.env.REACT_APP_FIREBASE_MESSAGING_SENDER_ID,
appId: process.env.REACT_APP_FIREBASE_APP_ID
})
export const auth = firebaseApp.auth()
export const db = firebaseApp.firestore()
export default firebaseAppNow import |
Beta Was this translation helpful? Give feedback.
The problem is with your
firebase.jsSince the var app can't be used for retrieving the data. You must declare a const variable tofirebaseAppand since you can't export two default variables I will suggest you to declare a constant variable and use that in your main code. So after changing all this stuffs yourfirebase.jsshould look like this