如何解决此错误:'Firebase'没有定义
我尝试在 React 上使用 firebase,但收到“'firebase'未定义”错误。 我安装了 firebase,并且在代码中导入的另一个文件上有 firebase 配置。 firebase 配置。
我的代码
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();
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();
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您混合使用了较旧的命名空间语法和较新的模块化语法。我建议从相关的 Firebase 文档开始,选择其中之一,而不是两者的组合。
v9 中的导入和获取服务为:
另请参阅 在 v9 SDK 中开始使用身份验证,开始使用和v9 SDK 中的 Firestore 和v9 SDK 升级指南。
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:
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.
您可以尝试在终端项目中写入 npm install -g firebase-tools
You can try write npm install -g firebase-tools in your terminal project