You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

TypeScript中Firebase Auth报错:找不到Persistence,该如何导入?

解决Firebase Auth中Cannot find name 'Persistence'的TypeScript错误

问题根源

你未从firebase/auth库中导入Persistence枚举,该枚举定义了Firebase Auth支持的持久化选项(LOCAL、SESSION、NONE),TypeScript无法识别未导入的标识符,因此抛出该错误。

修复方案

  1. 补充导入Persistence
    修改你的firebase/auth导入语句,添加Persistence:

    import {getAuth, GoogleAuthProvider, Auth, signInWithPopup, UserCredential, setPersistence, Persistence } from "firebase/auth";
    
  2. 修正函数名拼写错误
    你的函数_setPeristence存在拼写错误(persistence少了一个s),建议改为_setPersistence,避免后续调用时出现不必要的问题:

    const _setPersistence = async (): Promise<void> => {
        const app = _getApp();
        const auth = getAuth(app);
        setPersistence(auth, Persistence.LOCAL);
        return Promise.resolve();
    }
    

额外注意

  • 确保你使用的是Firebase v9及以上的模块化SDK,当前代码结构符合该版本的规范;旧版命名空间SDK的导入逻辑会有差异。
  • 同步修改SignIn函数中调用的函数名,将_setPeristence替换为修正后的_setPersistence。

内容的提问来源于stack exchange,提问作者user1730289

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.19 23:45:42