这是我的代码以及我尝试过的所有解决方案。
// import * as firebase from 'firebase'; //work around
import firebase from 'firebase/compat/app'; //work around (works?)
// import 'firebase/compat/auth'; //work around
// import 'firebase/firestore'; //work around
// import 'firebase/firestore'; //work around
// import { initializeApp } from 'firebase/app'; //work around
// import { initializeApp } from 'firebase/app';
// import firebase from '@firebase/app'; //work around
// require('firebase/auth'); //work around
// import firebase from 'firebase/app'; //work around
// import 'firebase/auth'; //work around
// console.log(firebase.auth); //word around
// import firebase from 'firebase/app';
// import 'firebase/firestore'; //work around
// import 'firebase/auth'; //work around
// import {initializeApp} from 'firebase/app'; //work around
// import {getFirestore, collection, getDocs} from 'firebase/firestore/lite'; //work around
// import {getAuth} from 'firebase/auth'; //work around
const firebaseConfig = {
apiKey: "AIzaSyBYZCeQfHboP-zEDyNGyMODEfx33RiQmTg",
authDomain: "graphqlmernstack.firebaseapp.com",
projectId: "graphqlmernstack",
storageBucket: "graphqlmernstack.appspot.com",
// messagingSenderId: "165123567996",
appId: "1:165123567996:web:6c808a04288956d188f4f9",
measurementId: "G-6G4BVK9FQZ"
};
// Initialize Firebase
firebase.initializeApp(firebaseConfig);
// const app = initializeApp(firebaseConfig); //work around
// const firebase = initializeApp(firebaseConfig); //work around
// const db = getFirestore(firebase); //work around
// const auth = getAuth(firebase); //work around
// const analytics = getAnalytics(app);
// console.log(auth);
export const auth = firebase.auth();
export const googleAuthProvider = new firebase.auth.GoogleAuthProvider();
如果有任何帮助,我将不胜感激,我已经尝试了几乎所有我找到的东西来让代码工作,正如你在上面的代码中看到的那样。
要解决此错误:
未捕获类型错误:firebase_compat_app__WEBPACK_IMPORTED_MODULE_0__.default.auth不是函数
您需要导入auth-compat库:
import 'firebase/compat/auth';
另请参阅v9 Firebase SDK及更高版本的升级指南。