react / react/metro

Dynamic imports do not respect watchFolders configuration

Open
#1,269 8 comments 3 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
JavaScript
Stars
5.6k
Forks
696
Avg merge
8m
Merged PRs (30d)
7

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the failure in a React Native project inside a Yarn v4 workspace, using the listed watchFolders setting and dynamic import of react-native-url-polyfill/auto. Trace Metro's dynamic-import resolution against the configured watchFolders; done means the module resolves successfully in this setup and a regression test covers it.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, nodejs, react-native
Domain
build-system, mobile, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.