【问题标题】:What am I doing wrong with this firebase snippet I found multiple times around the web?我在网上多次找到的这个 firebase 片段我做错了什么?
【发布时间】:2021-12-20 16:06:52
【问题描述】:

Property 'auth' does not exist on type 'typeof import("/home/nuhutuh25/Desktop/ignition/registry/node_modules/firebase/app/dist/app/index")'.ts(2339)

我确实安装了 firebase 作为依赖项,还看到有人成功编写了const auth=app.auth(),但这也不起作用,因为类型 FirebaseApp 没有属性 auth。

我正在使用打字稿。

【问题讨论】:

  • 本地安装firebase?什么?该项目是否包含 firebase 库?你在 package.json 中添加依赖了吗?
  • 哦,对不起,我的意思是我跑了 yarn add firebase

标签: typescript firebase firebase-authentication


【解决方案1】:

您似乎安装了新的 Firebase Modular SDK (V9.0.0+),它具有不同于旧名称空间的新语法。如果你想继续使用现有的语法,你可以切换到compat 版本:

import firebase from "firebase/compat/app"
import "firebase/compat/auth"

我会推荐upgrading to Modular SDK,因为兼容库是一个临时解决方案,将在未来的主要 SDK 版本中完全删除。

尝试重构您的代码,如下所示:

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";

const app = initializeApp({...firebaseConfig});

export const auth = getAuth(app);

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2017-09-29
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-12-07
    • 1970-01-01
    • 2020-08-30
    相关资源
    最近更新 更多