类型错误:调用“firebase.auth().onAuthStateChanged((user)”时无法读取未定义的属性“auth”
我是刚开始使用 react native 和 firebase,我遇到了这个错误:“TypeError:无法读取未定义的属性‘auth’”
我继续将我的代码附加到图像中:
我还继续复制和粘贴依赖项:
"dependencies": {
“@react-native-community/masked-view”:“0.1.10”,
“@react-navigation/bottom-tabs”:“~5.2.6”,
“@react-navigation/native”:“~5.1.5”,
“@react-navigation/stack”:“~5.2.10”,
“expo”:
“~42.0.1”
“expo-status-bar”:“~1.0.4”
“firebase”:“^9.1.2”
“react”:“16.13.1”
“react-dom”:“16.13.1”
“react-native”:“https://github.com/expo/react-native/archive/sdk-42.0.0.tar.gz”
“react-native-elements”:“^3.4.2”
“react-native-gesture-handler”:“~1.10.2”
“react-native-reanimated”:“~2.2.0”
“react-native-router-flux”
“3.36.0”,
“react-native-safe-area-context”:“^3.3.2”,
“react-native-screens”:“~3.4.0”,
“react-native-vector-icons”:“^8.1.0”,
“react-native-web”:“~0.13.12”
},
您正在使用 Firebase Modular SDK,它具有全新的语法,您还需要导入 Firebase Auth。要继续使用现有代码,您可以尝试将导入更改为以下内容:
import firebase from 'firebaser/compat/app'
import 'firebase/compat/auth'
我建议 升级到 Modular SDK ,因为它有诸多好处,并且兼容版本将很快被移除。