Firebase v9模块化-无法找到变量:IDBIndex

2022-07-25 00:00:00 firebase javascript react-native expo

我正在使用Reaction Native和EXPO,我正在尝试使用Firebase V9(模块化版本)。每当我尝试在配置文件之外使用Firebase函数时,我都会遇到错误。例如,我在Firebase.tsx中有signUpWithEmail函数,但当我尝试在我的SignUpScreen.tsx中使用它时,它会给我一个
找不到变量:IDBIndex。
似乎与我的节点模块有关??
可能是错误的版本?
我也没有启用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异常
在句柄中的node_modules/react-native/Libraries/Core/ExceptionsManager.js:172:19异常
At node_modules/react-native/Libraries/Core/setUpErrorHandling.js:24:6 in HandleError
错误使用中的at node_modules/@react-native/polyfills/error-guard.js:49:36。reportFatalError
在GuardedLoadModule中的node_modules/metro-runtime/src/polyfills/require.js:204:6
在全局代码中http://192.168.1.189:19000/node_modules/expo/AppEntry.bundle?platform=ios&dev=true&hot=false&strict=false&minify=false:140947:3


解决方案

我很高兴您终于摆脱了这个问题,似乎Firebase 9版本有一些问题,我在这里发现了一些问题https://github.com/expo/expo-cli/issues/3066解决方案,基本上是将Firebase版本降级到7或8。

相关文章