I'm trying to use firebase on react, but I'm getting the " 'firebase' is not defined " error. I installed firebase, and I have the firebase configuration on another file that I import on the code. The firebaseConfig.
My code
import { initializeApp } from 'firebase/app';
import { firebaseConfig } from "./config";
import 'firebase/auth';
import 'firebase/firestore';
const app = initializeApp(firebaseConfig);
const auth = auth(firebase.auth);
const firestore = firestore(firebase.firestore);
const GoogleProvider = new firebase.auth.GoogleAuthProvider();
GoogleProvider.setCustomParameters({ prompt: 'select_account' });
export const signInWithGoogle = () => auth.signInWithPopup();
CodePudding user response:
You're using a mix of the older namespaces syntax, and the newer modular syntax. I recommend starting from the relevant Firebase documentation and picking one of the other, not a combination of both.
The imports and getting services in v9 are:
import { initializeApp } from 'firebase/app';
import { firebaseConfig } from "./config";
import { getAuth } from 'firebase/auth';
import { getFirestore } from 'firebase/firestore';
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
const firestore = getFirestore(app);
Also see the Firebase documentation on getting started with Auth in the v9 SDK, getting starting with Firestore in the v9 SDK and the upgrade guide to the v9 SDK.
CodePudding user response:
You can try write npm install -g firebase-tools in your terminal project