Giter Site home page Giter Site logo

Comments (7)

huntie avatar huntie commented on May 5, 2024 3

Confirming @EvanBacon's suspicions, @firebase/auth specifies top-level "react-native" and "browser" fields in its package manifest, which causes Metro to select the dist/rn/index.js module (which does not export browserLocalPersistence).

https://github.com/firebase/firebase-js-sdk/blob/784607676ebe9889e99c1c735173549dcda0fd7c/packages/auth/package.json#L7-L8

Workarounds for app devs

  • If the project is web-only, overriding resolver.resolverMainFields to a value of ['browser', 'main'] will no longer resolve "react-native" exports across packages.

  • Configuring resolver.resolveRequest as documented will allow you to set a specific override for imports of 'firebase/auth' β€”Β perhaps to either of the following files within node_modules/@firebase/auth/.

    "browser": "dist/esm2017/index.js",
    "cordova": "dist/cordova/index.js",

Follow-ups

  • On the Firebase side, submitting a PR updating index.rn.js in @firebase/auth to expose browserLocalPersistence (citing that this enables use in react-native-web) will fix this issue for others under Metro's current behaviour.
  • On the Metro side, we are actively reviewing the behaviours of the top-level "react-native" and "browser" package.json fields. The rollout of Expo Web with Metro is making issues like this visible, which may motivate us towards a short term config escape hatch β€” before a revision to this behaviour (where we will not overlap "react-native" and "browser") coming with support for package "exports".

cc @motiz88 @robhogan

from router.

EvanBacon avatar EvanBacon commented on May 5, 2024 1

Unrelated to the router, but my first guess would be that firebase is using react-native import fields in the package.json and don't account for Metro web. I'm not sure if Metro allows for swapping the resolver main fields dynamically based on platform but I could check.

from router.

Albert-Gao avatar Albert-Gao commented on May 5, 2024 1

Thanks so much for your time: @huntie
It's a web+native project. I will try the 2nd workaround(resolver.resolveRequest) for now :)

created a PR on firebase side: firebase/firebase-js-sdk#6683

from router.

austin43 avatar austin43 commented on May 5, 2024 1

@Albert-Gao I'm struggling with this one too, as there's sparse examples for how to use metro resolver.resolveRequest. Our use-case is to have signInWithPopup and signInWithRedirect from firebase/auth. As of [email protected] it stopped working.

resolverMainFields works without EXPO_METRO_NO_MAIN_FIELD_OVERRIDE for me on web.

We have a native app too though so the first option is not viable.

Could you share what you used for resolveRequest?

from router.

Albert-Gao avatar Albert-Gao commented on May 5, 2024

Indeed, not related to the router directly, but since the metro is a critical component of expo router. I posted here πŸ˜„ will do more digging later

from router.

Albert-Gao avatar Albert-Gao commented on May 5, 2024

Updated the example to the latest version and cross-posted this issue in metro repo :)
facebook/metro#878

from router.

Albert-Gao avatar Albert-Gao commented on May 5, 2024

Thanks for the fix! @EvanBacon

https://github.com/expo/expo/pull/19529/files

according to the code, it should be fallback to the preferredMainFields when EXPO_METRO_NO_MAIN_FIELD_OVERRIDE ===false
image

however, I tried it, still undefined

image

I am using this script,

{
  "scripts": {
    "web": "EXPO_METRO_NO_MAIN_FIELD_OVERRIDE=false npx expo start --dev-client --web"
  },
}

What am I missing here? :)

from router.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    πŸ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. πŸ“ŠπŸ“ˆπŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❀️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.