简体   繁体   English

firebase auth: TypeError: (0, _reactNative.getReactNativePersistence) 不是 function。react-native EXPO

[英]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.

相关问题 Firebase 使用 React Native 进行电话身份验证 Expo - Firebase Phone Auth with React Native Expo React Native - Expo 错误 - “在‘firebase’中找不到导出‘auth’: - React Native - Expo Error - "export 'auth' was not found in 'firebase' : undefined 不是 object on react-native expo with firestore - undefined is not an object on react-native expo with firestore Auth state 即使在卸载并重新安装后仍然坚持 react-native(iOS)! 使用 Firebase 认证 - Auth state still persisting in react-native(iOS) even after uninstalling and reinstalling! Using Firebase Auth Expo react-native app with firebase phone authentication works on web, error on ios simulator and crashes with no warning on Android - Expo react-native app with firebase phone authentication works on web, error on ios simulator and crashes with no warning on Android Firebase 是 react-native 后端 - Firebase are react-native backend React Native Expo. Azure 授权 - React Native Expo. Azure auth 如何使用 react-native 和 expo 将 m4a 音频文件上传到 Firebase 存储? - How does one upload an m4a audio file to Firebase Storage using react-native and expo? 我应该安装哪个版本的node,react-native、expo、firebase等,才不会出现依赖问题? - Which version should I install node, react-native, expo, firebase, etc. so that there are no dependency problems? 混淆将 react-native-firebase 与 Expo 集成 - Confusion integrating react-native-firebase with Expo
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM