【问题标题】:TypeScript import statement cannot find Firebase module in Expo projectTypeScript 导入语句在 Expo 项目中找不到 Firebase 模块
【发布时间】:2021-10-28 01:45:05
【问题描述】:

我正在启动一个全新的 Expo 项目,并遵循 2021 年 8 月 28 日发布的所有文档。Firebase 文档指定的导入语句不起作用。以下是重现的步骤。

expo init firebase-demo

选择blank (TypeScript) 并回车。

cd firebase-demo
expo install firebase

将此行添加到 App.tsx,如 docs 所说:

import { getAuth, createUserWithEmailAndPassword } from "firebase/auth";

您会收到此错误:模块“firebase/auth”没有导出成员“getAuth”。

关于出了什么问题的线索是,在 VS Code 中,如果我通过命令单击 "firebase/auth",它会打开 node_modules/firebase/empty-import.d.ts,其全部内容是:

declare namespace empty {}
export = empty;

有一个 node_modules/firebase/auth 目录。为什么导入语句没有发现?

这是我的 tsconfig.json,我没有根据 expo init 创建的内容进行修改:

{
  "extends": "expo/tsconfig.base",
  "compilerOptions": {
    "strict": true
  }
}

【问题讨论】:

    标签: typescript firebase firebase-authentication expo


    【解决方案1】:

    我遇到了同样的问题。我的解决方案是:

    添加:"exclude": ["node_modules", "node_modules/**/*"] 给你的jsconfig.json 然后Ctrl+Shift+P -> Reload window

    我遇到的另一个解决方案:

    做同样的事情,但在编辑 jsconfig.json 之前从项目中删除 node_modules 文件夹并在 Ctrl+Shift+P -> Reload Window 之后运行 npm install

    【讨论】:

      【解决方案2】:

      我通过将 firebase 升级到 9.0.0 解决了这个问题。这个问题似乎是由于expo install firebase 安装了一个相当旧的版本 - 8.2.3,从 7 个月前开始。当前版本是 9.0.0,当前的文档大概就是为了这个。我将谨慎行事,因为 9.0.0 未经认证可与 Expo 一起使用。 (我想另一种可能的解决方案是查找 8.2.3 的文档)。

      【讨论】:

        猜你喜欢
        • 2016-07-05
        • 2022-06-24
        • 1970-01-01
        • 2023-04-02
        • 2022-10-16
        • 2021-09-01
        • 2020-07-14
        • 2016-06-05
        • 1970-01-01
        相关资源
        最近更新 更多