簡體   English   中英

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

[英]firebase auth: TypeError: (0, _reactNative.getReactNativePersistence) is not a function. react-native EXPO

我將expo用於react-native ,並希望在我的 react-native 應用程序中初始化firebase 身份驗證 有以下錯誤需要修復:

TypeError: (0, _reactNative.getReactNativePersistence) is not a function. (In '(0, _reactNative.getReactNativePersistence)(_asyncStorage.default)', '(0, _reactNative.getReactNativePersistence)' is undefined)

我的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};

這是我的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
}

我正在使用 Firebase 9.1,因為 EXPO 的文檔建議這樣做。 我使用 _reactNative.getReactNativePersistence 的原因是為了防止警告:

Firebase on React Native should import AsyncStorage from @react-native-community/async-storage

作為參考,您可以在此處找到警告問題: Issue

錯誤

在 Firebase v9.4.1中添加了getReactNativePersistence() 您的package.json不清楚可讀,但似乎是9.1.0 嘗試使用npm i firebase@latest更新到最新版本。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM