[英]firebase auth: TypeError: (0, _reactNative.getReactNativePersistence) is not a function. react-native EXPO
I use expo for react-native and want to initialize firebase auth in my react-native app.我将expo用于react-native ,并希望在我的 react-native 应用程序中初始化firebase 身份验证。 There is the following error to fix:
有以下错误需要修复:
TypeError: (0, _reactNative.getReactNativePersistence) is not a function. (In '(0, _reactNative.getReactNativePersistence)(_asyncStorage.default)', '(0, _reactNative.getReactNativePersistence)' is undefined)
My firebase init file is the following:我的firebase 初始化文件如下:
import { initializeApp, FirebaseApp, getApps, getApp } from 'firebase/app';
import { Auth, getAuth, initializeAuth } from 'firebase/auth';
import { getReactNativePersistence } from 'firebase/auth/react-native';
import AsyncStorage from '@react-native-async-storage/async-storage';
import { initializeFirestore } from "firebase/firestore";
import { getStorage } from "firebase/storage";
// Your web app's Firebase configuration
const firebaseConfig = {
...app
};
let app;
let auth;
if (getApps().length < 1) {
app = initializeApp(firebaseConfig);
auth = initializeAuth(app, {
persistence: getReactNativePersistence(AsyncStorage),
});
} else {
app = getApp();
auth = getAuth();
}
const db = initializeFirestore(app, {
experimentalForceLongPolling: true,
});
const storage = getStorage(app);
export {db, auth, storage};
Here is my package.json file:这是我的package.json文件:
{
"name": "...",
"version": "1.0.0",
"main": "node_modules/expo/AppEntry.js",
"scripts": {
"start": "expo start",
"android": "expo start --android",
"ios": "expo start --ios",
"web": "expo start --web"
},
"dependencies": {
"@react-native-firebase/app": "~15.4.0",
"@react-native-segmented-control/segmented-control": "^2.4.0",
"@react-navigation/bottom-tabs": "^6.3.3",
"@react-navigation/native-stack": "^6.8.0",
"expo": "~46.0.9",
"expo-av": "~12.0.4",
"expo-camera": "~12.3.0",
"expo-linear-gradient": "~11.4.0",
"expo-status-bar": "~1.4.0",
"expo-video-thumbnails": "~6.4.0",
"firebase": "^9.1.0",
"lottie-react-native": "5.1.3",
"react": "18.0.0",
"react-native": "0.69.6",
"react-native-animatable": "^1.3.3",
"react-native-expo-cached-image": "^1.3.1",
"react-native-keyboard-aware-scroll-view": "^0.9.5",
"styled-components": "^5.3.5",
"@react-native-async-storage/async-storage": "~1.17.3"
},
"devDependencies": {
"@babel/core": "^7.12.9"
},
"private": true
}
I am using Firebase 9.1 because the documentation of EXPO recommend to do so.我正在使用 Firebase 9.1,因为 EXPO 的文档建议这样做。 The reason why I use the _reactNative.getReactNativePersistence is to prevent the warning:
我使用 _reactNative.getReactNativePersistence 的原因是为了防止警告:
Firebase on React Native should import AsyncStorage from @react-native-community/async-storage
As a reference you find here the issue to the warning: Issue作为参考,您可以在此处找到警告问题: Issue
The getReactNativePersistence()
was added in Firebase v9.4.1
.在 Firebase
v9.4.1
中添加了getReactNativePersistence()
。 Your package.json
isn't clearly readable but that seems to be 9.1.0
.您的
package.json
不清楚可读,但似乎是9.1.0
。 Try updating to latest version using npm i firebase@latest
.尝试使用
npm i firebase@latest
更新到最新版本。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.