facebook / metro

🚇 The JavaScript bundler for React Native
https://metrobundler.dev
MIT License
5.25k stars 626 forks source link

Async import (lazy bundling) fails to resolve in a monorepo with React Native version 0.73-0.76 (Android only) #1262

Open Bob-FE opened 7 months ago

Bob-FE commented 7 months ago

Do you want to request a feature or report a bug? bug

What is the current behavior? Dynamic import fails to resolve in a monorepo with React Native version 0.74.0

If the current behavior is a bug, please provide the steps to reproduce and a minimal repository on GitHub that we can yarn install and yarn test. I have a min-size demo here https://github.com/Bob-FE/bare-rn-0740-monorepo

What is the expected behavior? can resolve module with dynamic import

RuudBurger commented 1 month ago

Would love a response on this. Upgrading to RN 0.75 and we had to move all our dynamic imports back to normal imports to get it working.

robhogan commented 1 month ago

Hi folks - has anyone experienced this in iOS? I'm looking into it now and it appears to be an Android-specific issue with URLs getting mangled.

The change that triggered this is most likely https://github.com/facebook/react-native/pull/37003 (RN 0.73.0), which causes await import() to become a bundle-splitting boundary, with the separate piece being loaded in a separate HTTP request to Metro.

In monorepos, the path may begin ../<something>.bundle, and it looks like Android is dropping the ../.

robhogan commented 1 month ago

(I should add that the repro uses babel-plugin-module-resolver, which we don't recommend/support and may cause issues on both iOS and Android, but the issue is reproducible without that on Android)

RuudBurger commented 1 month ago

Android only on our side. I usually do dev on iOS and only noticed at the end when I started testing on Android.