【问题标题】:property 'database' does not exist on type 'firebaseapp' ts(2339)类型“firebaseapp”ts(2339) 上不存在属性“数据库”
【发布时间】:2021-11-16 12:04:12
【问题描述】:

我正在尝试在我的 typescript react 应用程序中实现 firebase 的实时数据库,基于此 Medium 帖子:https://levelup.gitconnected.com/todo-app-using-firebase-react-typescript-ea0a34bd417d

在配置步骤中,我得到错误属性 'database' does not exist on type 'firebaseapp' ts(2339)

我搜索了错误但找不到答案,有人可以帮忙吗? 这是我第一次问问题,如果我的问题给您带来任何不便,我很抱歉,非常感谢你们的帮助

【问题讨论】:

    标签: typescript firebase firebase-realtime-database


    【解决方案1】:

    Firebase 最近发布了new Modular SDK V9,它提高了性能,同时使用了新的语法。大多数旧教程都遵循V8,如果您想遵循它们,请将导入更改为compat 版本:

    import firebase from 'firebase/compat/app'
    import 'firebase/compat/database'
    // import 'firebase/compat/[SERVICE]'
    

    但是,我强烈建议升级到新语法并遵循documentation,其中包含V8V9 的示例。新语法如下:

    import { initializeApp } from 'firebase/app' // no compat for new SDK
    import { getDatabase, ref } from 'firebase/database'
    
    const config = {...}
    
    const app = initializeApp(config)
    
    const database = getDatabase(app)
    
    export const todosRef = ref(database, "todos")
    

    【讨论】:

    • 这对我有用,非常感谢您的帮助
    猜你喜欢
    • 2021-01-10
    • 2019-08-11
    • 2021-08-02
    • 2020-06-02
    • 2022-07-09
    • 2022-10-04
    • 2023-02-07
    • 2020-08-23
    • 2021-12-19
    相关资源
    最近更新 更多