metro icon indicating copy to clipboard operation
metro copied to clipboard

Dynamic imports do not respect watchFolders configuration

Open taylorkline opened this issue 2 months ago • 6 comments

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

A bug

What is the current behavior?

Dynamic import fails to resolve:

Error: Unable to resolve module ./node_modules/react-native-url-polyfill/auto from .../packages/mobile/.:

None of these files exist:
  * node_modules/react-native-url-polyfill/auto(.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)
  * node_modules/react-native-url-polyfill/auto/index(.android.js|.native.js|.js|.android.jsx|.native.jsx|.jsx|.android.json|.native.json|.json|.android.ts|.native.ts|.ts|.android.tsx|.native.tsx|.tsx)

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.

  1. Initialize a React Native project
  2. Place it within a yarn v4 monorepo as a workspace
  3. Install react-native-url-polyfill in the react native workspace
    • Configure watchFolders to include ../../: watchFolders: [path.resolve(__dirname, "../../")],
  4. Ensure react-native-url-polyfill exists at ../../node_modules/react-native-url-polyfill
  5. Add dynamic import import("react-native-url-polyfill/auto")

I'm sorry, I do not have time to create a reproducible example repo right now.

What is the expected behavior?

Dynamic import should resolve successfully.

Please provide your exact Metro configuration and mention your Metro, node, yarn/npm version and operating system.

System:
  OS: macOS 14.4.1
  CPU: (12) arm64 Apple M3 Pro
  Memory: 151.80 MB / 18.00 GB
  Shell:
    version: "5.9"
    path: /bin/zsh
Binaries:
  Node:
    version: 18.20.2
    path: ~/Library/Caches/fnm_multishells/49824_1714674459208/bin/node
  Yarn:
    version: 4.1.1
    path: ~/Library/Caches/fnm_multishells/49824_1714674459208/bin/yarn
  npm:
    version: 10.5.0
    path: ~/Library/Caches/fnm_multishells/49824_1714674459208/bin/npm
  Watchman:
    version: 2024.01.22.00
    path: /opt/homebrew/bin/watchman
Managers:
  CocoaPods:
    version: 1.14.3
    path: /Users/taylor/.rbenv/shims/pod
SDKs:
  iOS SDK:
    Platforms:
      - DriverKit 23.4
      - iOS 17.4
      - macOS 14.4
      - tvOS 17.4
      - visionOS 1.1
      - watchOS 10.4
  Android SDK:
    API Levels:
      - "26"
      - "28"
      - "29"
      - "30"
      - "31"
      - "32"
      - "33"
      - "34"
    Build Tools:
      - 23.0.1
      - 25.0.2
      - 25.0.3
      - 27.0.3
      - 28.0.0
      - 28.0.3
      - 29.0.2
      - 29.0.3
      - 30.0.2
      - 30.0.3
      - 31.0.0
      - 33.0.0
      - 33.0.1
      - 34.0.0
      - 35.0.0
      - 35.0.0
    System Images:
      - android-21 | Google APIs Intel x86 Atom_64
      - android-29 | Intel x86 Atom_64
      - android-29 | Google APIs ARM 64 v8a
      - android-29 | Google Play Intel x86 Atom
      - android-30 | Google APIs Intel x86 Atom
      - android-30 | Google Play Intel x86 Atom
      - android-33 | Google APIs Intel x86_64 Atom
    Android NDK: Not Found
IDEs:
  Android Studio: 2023.2 AI-232.10227.8.2321.11479570
  Xcode:
    version: 15.3/15E204a
    path: /usr/bin/xcodebuild
Languages:
  Java:
    version: 17.0.10
    path: /usr/bin/javac
  Ruby:
    version: 3.3.0
    path: /Users/taylor/.rbenv/shims/ruby
npmPackages:
  "@react-native-community/cli": Not Found
  react: Not Found
  react-native: Not Found
  react-native-macos: Not Found
npmGlobalPackages:
  "*react-native*": Not Found
Android:
  hermesEnabled: true
  newArchEnabled: false
iOS:
  hermesEnabled: true
  newArchEnabled: false

taylorkline avatar May 02 '24 18:05 taylorkline