skip to Main Content

I cannot import the getReactNativePersistence module from the firebase/auth. I’m using Typescript.

Importing the function as below was possible, but it didn’t work when I updated the Firebase SDK from 9.22.0 to 10.1.0.

import { getReactNativePersistence } from "firebase/auth/react-native";

It seems like there is no firebase/auth/react-native anymore.

I also tried the following code, as the document indicates,

import { getReactNativePersistence } from "firebase/auth";

But it throws an error.

Module '"firebase/auth"' has no exported member 'getReactNativePersistence'.

I’m using Expo, which uses Metro as default.

This is my metro.config.js

// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');

module.exports = getDefaultConfig(__dirname);

How can I import getReactNativePersistence in [email protected]?

2

Answers


  1. If I understand facebook/metro#807 correctly (as mentioned in firebase/firebase-js-sd#7138), you need to update your Metro config to the following:

    // metro.config.js
    const { getDefaultConfig } = require('expo/metro-config');
    
    // initialize configuration
    const config = getDefaultConfig(__dirname);
    config.resolver.resolverMainFields = ['react-native', 'browser', 'main'];
    
    module.exports = config;
    
    Login or Signup to reply.
  2. My solution was to copy the getReactNativePersistence implementation from here: https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/src/platform_react_native/persistence/react_native.ts, and the common types from here https://github.com/firebase/firebase-js-sdk/blob/master/packages/auth/src/core/persistence/index.ts
    into an internal file in the project, and then replacing the getReactNativePersistence references with my own local version.

    The code is simple enough that I didn’t see a problem maintaining it myself.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search