我正在使用 React Native 和 Expo,并尝试使用 Firebase V9(模块化版本)。每当我尝试在配置文件之外使用 firebase 函数时,我都会遇到错误。例如,我有signUpWithEmail
firebase.tsx 中的函数,但是当我尝试在 SignUpScreen.tsx 中使用它时,它给了我一个
找不到变量:IDBIndex.
似乎与我的node_modules有关?
也许版本错误?
我也没有启用 Google Analytics。
这是我的代码文件:
firestore.ts:
import { initializeApp } from 'firebase/app';
import { createUserWithEmailAndPassword, getAuth } from 'firebase/auth';
import Constants from 'expo-constants';
const firebaseConfig = {
apiKey: Constants.manifest?.extra?.firebaseApiKey,
authDomain: Constants.manifest?.extra?.firebaseAuthDomain,
projectId: Constants.manifest?.extra?.firebaseProjectId,
storageBucket: Constants.manifest?.extra?.firebaseStorageBucket,
messagingSenderId: Constants.manifest?.extra?.firebaseMessagingSenderId,
appId: Constants.manifest?.extra?.firebaseAppId,
};
const app = initializeApp(firebaseConfig);
const auth = getAuth(app);
// AUTHENTICATION // ---------------------------------------------------------
export const signUpWithEmail = async (fName: string, lName: string, email: string, password: string) => {
try {
await createUserWithEmailAndPassword(auth, email, password);
console.log('Success!')
} catch (e) {
console.log(e);
}
}
SignUpScreen.tsx:
import React, { useState } from 'react';
import { StyleSheet, View} from 'react-native';
import MyButton from '../components/MyButton';
import MyField from '../components/MyField';
import { signUpWithEmail } from '../services/firebase';
export default function SignUpScreen() {
const [fName, setFName] = useState("");
const [lName, setLName] = useState("");
const [email, setEmail] = useState("");
const [password, setPassword] = useState("");
return (
<View style={styles.container}>
<MyField title='First Name' type='text' onChangeFn={setFName}/>
<MyField title='Last Name' type='text' onChangeFn={setLName}/>
<MyField title='Email' type='text' onChangeFn={setEmail}/>
<MyField title='Password' type='text' onChangeFn={setPassword}/>
<MyButton text="Sign Up" type="primary" size="large" onPressFn={
() => { signUpWithEmail(fName, lName, email, password) }} />
</View>
);
}
const styles = StyleSheet.create({
container: {
flex: 1,
backgroundColor: '#fff',
alignItems: 'center',
justifyContent: 'center',
},
fixToText: {
flexDirection: 'column',
justifyContent: 'space-between',
alignItems: 'center',
},
});
这是我运行应用程序时的错误:
ReferenceError:找不到变量:IDBIndex
在 node_modules/react-native/Libraries/Core/ExceptionsManager.js:104:6 中的 reportException
在node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19中handleException
在 node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 中的handleError
在 ErrorUtils.reportFatalError 中的 node_modules/@react-native/polyfills/error-guard.js:49:36
在node_modules/metro-runtime/src/polyfills/require.js:204:6 在guardedLoadModule
at 在全局代码中