Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

React Native Macos overrides resolveRequest property of resolver in Metro config #2123

Open
tjzel opened this issue May 17, 2024 · 2 comments
Labels
bug Something isn't working Needs: Triage 🔍

Comments

@tjzel
Copy link

tjzel commented May 17, 2024

Environment

react-native -v: 0.73.4
npm ls react-native-macos: 0.73.26
node -v: 20.11.0
npm -v: 10.2.3
yarn --version: 4.1.1
xcodebuild -version: Xcode 15.4 Build version 15F31d

Steps to reproduce the bug

When dealing with more complicated project configurations, namely monorepos, Metro has to be configured to prevent all sort of issues, like duplicated modules, correct resolving etc.

You can see an example of such setup in react-native-screens repo.

React Native Reanimated tries to actively support macOS. However, we are currently in the process of a migration to a monorepo setup and I noticed that resolveRequest function gets overridden by react-native-macos. This might cause the Metro bundler to fail or to duplicate some modules.

As a simple reproduction, you can create an App using react-native-macos and paste this into your metro.config.js:

const {getDefaultConfig, mergeConfig} = require('@react-native/metro-config');

/**
 * Metro configuration
 * https://facebook.github.io/metro/docs/configuration
 *
 * @type {import('metro-config').MetroConfig}
 */
const config = {
  resolver: {
    resolveRequest: () => {
      console.log('resolveRequest');
    },
  },
};

module.exports = mergeConfig(getDefaultConfig(__dirname), config);

You will notice that nothing ever gets logged and module resolution doesn't fail, although it should.

Expected Behavior

User provided requestResolve function is acknowledged and used.

Actual Behavior

User provided requestResolve is not used.

Reproducible Demo

No response

Additional context

I understand that you might have the need of having your own custom resolveRequest function. However, this should not completely override the user's function.

For now we can solve the issue in our repository by patch-package. I'd be grateful if you could point me to the place in your code where you override the requestResolve function so we can properly embed react-native-macos in our new monorepo setup.

@tjzel tjzel added the bug Something isn't working label May 17, 2024
@Saadnajmi
Copy link
Collaborator

@tido64 / @acoates-ms any opinions here?

@tido64
Copy link
Member

tido64 commented May 20, 2024

Sorry, I'm a bit confused. Where does this override happen in react-native-macos? I've tried looking at the code but the only place I found that even sets resolver is in @react-native/community-cli-plugin. Furthermore, I'm pretty sure we use resolveRequest ourselves internally to support symlinks and other scenarios.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Needs: Triage 🔍
Projects
None yet
Development

No branches or pull requests

3 participants