React Native Expo: TypeError: undefined不是createUserWithEmail



我正在使用Expo和Firebase开发React Native应用程序。我试图使用createUserWithEmailAndPassword函数来创建一个具有电子邮件和密码身份验证的新用户。但是,我遇到了以下错误:

TypeError: undefined is not a function, js engine: Hermes

此错误似乎与createUserWithEmailAndPassword函数有关。我一直在搜索Expo和Firebase文档,但我还没有找到合适的解决方案。下面是我使用的代码:

firebase.js:

import { initializeApp } from "firebase/app";
import { getAuth } from "firebase/auth";
const firebaseConfig = {
apiKey:,
authDomain: ,
projectId: ,
storageBucket: ,
messagingSenderId: ,
appId: ,
measurementId:,
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
export default { auth };

SignUp.js:

import auth from "../firebase/firebase";
function createUser() {
auth.createUserWithEmailAndPassword(email, password).then(() => {
console.log("worked");
});
}

是否有Hermes JavaScript引擎和Firebase Web SDK之间的兼容性问题?还是有其他解决办法?

任何帮助将不胜感激!

const app = getYourFirebaseApp()
const auth = getAuth(app);
const result = await createUserWithEmailAndPassword(
auth,
email,
password
);

这是它的类型

createUserWithEmailAndPassword(auth: Auth, email: string, password: string): Promise<UserCredential>

在我的firebase.js文件中,我更改了export语句,为应用程序和auth对象使用命名导出:

// Initialize Firebase
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
export { app, auth }; // Update this line to use named exports

通过使用命名的导出并正确导入auth对象,我能够解决undefined"的&;TypeError;错误,并成功使用Firebase认证创建新用户。

最新更新