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

Firebase createUserWithEmailAndPassword报undefined错误,Android项目缺失对应模块

问题

调用handleSignUp函数时触发undefined错误,但Firebase控制台显示用户账号已成功创建,且通过console.log("user mail at signup", user);能正常输出用户信息。此前该功能运行正常,即使注释掉这条console.log语句后的所有代码,错误仍然会出现。

错误信息如下:

Error signing up: You attempted to use a firebase module that's not installed on your Android project by calling firebase.app(). Ensure you have: 1) imported the 'io.invertase.firebase.app.ReactNativeFirebaseAppPackage' module in your 'MainApplication.java' file. 2) Added the 'new ReactNativeFirebaseAppPackage()' line inside of the RN 'getPackages()' method list.

附handleSignUp函数代码:

const handleSignUp = async () => {
    try {
      if (macAdd.length !== 12) {
        Alert.alert(t("signupFailed"), t("shortMacAdd"));
        return;
      }

      const userCredential = await createUserWithEmailAndPassword(
        auth,
        email,
        password
      );

      const user = userCredential.user;
      console.log("user mail at signup", user);
      await updateProfile(user, { displayName: macAdd });

      const token = await messaging().getToken();
      const dataRef = ref(database, macAdd + "/");
      await update(dataRef, { FCM_token: token });
      console.log("FCM_token", token);

      setIsDialog1Visible(true);
    } catch (err) {
      console.error("Error signing up:", err.code);
      if (err.code === "auth/email-already-in-use") {
        Alert.alert(t("signupFailed"), t("auth/email-already-in-useBody"));
      } else if (err.code === "auth/invalid-email") {
        Alert.alert(t("signupFailed"), t("auth/invalid-emailBody"));
      } else if (err.code === "auth/weak-password") {
        Alert.alert(t("signupFailed"), t("auth/weak-passwordBody"));
      } else if (err.code === "auth/missing-password") {
        Alert.alert(t("signupFailed"), t("auth/missing-passwordBody"));
      } else {
        Alert.alert(t("signupFailed"), t("otherErrorSignup"));
      }
    }
  };

解决方法

根据错误提示,问题出在Android项目中Firebase核心模块未正确配置,按以下步骤排查修复:

  • 检查MainApplication.java文件:

    1. 确认已导入io.invertase.firebase.app.ReactNativeFirebaseAppPackage
    2. 确认在getPackages()方法的返回列表中添加了new ReactNativeFirebaseAppPackage()
  • 补充排查操作:

    1. 清理Android项目缓存:执行cd android && ./gradlew clean命令,之后重新构建项目
    2. 确保所有React Native Firebase相关依赖的版本保持一致,避免版本不兼容导致的初始化问题
    3. 验证auth实例是否正确初始化,确认Firebase核心应用在调用createUserWithEmailAndPassword前已完成初始化

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.30 17:50:26