feat: Expose MetroConfig type directly from @react-native/metro-config#46602
Closed
tjzel wants to merge 1 commit into
Closed
feat: Expose MetroConfig type directly from @react-native/metro-config#46602tjzel wants to merge 1 commit into
tjzel wants to merge 1 commit into
Conversation
robhogan
approved these changes
Sep 23, 2024
Contributor
|
@robhogan has imported this pull request. If you are a Meta employee, you can view this diff on Phabricator. |
Contributor
Collaborator
|
This pull request was successfully merged by @tjzel in cc6d1eb When will my fix make it into a release? | How to file a pick request? |
blakef
pushed a commit
that referenced
this pull request
Oct 7, 2024
#46602) Summary: React Native [app template provided by the CLI](https://github.com/react-native-community/template) currently uses [`metro-config` directly for `MetroConfig` type](https://github.com/react-native-community/template/blob/main/template/metro.config.js#L7). However, it doesn't have `metro-config` as neither a dependency or dev dependency, which can lead to version mismatches. While this is obviously a mistake on the template repo side, `metro-config` versions aren't matched with `react-native` versions. Therefore, getting the correct version of `metro-config` from `react-native/metro-config` would require reflecting on `react-native/metro-config`'s package.json etc. which is far from ideal. In my opinion it's would be much better to expose `MetroConfig` type from `react-native/metro-config` directly. Version mismatching can happen in a monorepo setup. Say we have the monorepo structure using Yarn Modern: ```tree . ├── RN75-app (workspace) ├── RN76-app (workspace) │ ├── metro.config.js │ └── node_modules │ └── react-native │ └── metro-config (0.76) │ └── node_modules │ └── metro-config (version for 0.76) └── node_modules ├── react-native │ └── metro-config (0.75) └── metro-config (version for 0.75) ``` `react-native@0.75` gets hoisted to the monorepo root while `react-native@0.76` sits in an RN 0.76 app workspace. Say we have the following `RN76-app/metro.config.js` contents: ```js const {getDefaultConfig, mergeConfig} = require('react-native/metro-config'); /** * Metro configuration * https://reactnative.dev/docs/metro * * type {import('metro-config').MetroConfig} */ const config = {}; module.exports = mergeConfig(getDefaultConfig(__dirname), config); ``` In this case, `require('react-native/metro-config')` would resolve to `RN76-app/node_modules/react-native/node_modules/metro-config` since `react-native/metro-config` is a (dev) dependency of the App. However `import('metro-config).MetroConfig` would resolve to `node_modules/metro-config` since it's not a direct dependency. This is how we have a mismatch - imported functions come from different packages than imported type. ## Changelog: [GENERAL] [ADDED] - Expose `MetroConfig` type directly from `react-native/metro-config`. Pull Request resolved: #46602 Test Plan: `yarn build` to generate dist for `react-native/metro-config`, see it has the export of `MetroConfig`. ## Notes If this PR gets approved, I'll submit relevant one to the CLI template. Reviewed By: huntie Differential Revision: D63258881 Pulled By: robhogan fbshipit-source-id: e6f3c880eb4a0aa902c62932d58f243c38b07c2e
Collaborator
|
This pull request was successfully merged by @tjzel in 273ad9c When will my fix make it into a release? | How to file a pick request? |
github-merge-queue Bot
pushed a commit
to software-mansion/react-native-reanimated
that referenced
this pull request
Nov 18, 2024
## Summary Since - facebook/react-native#46602 got merged we can apply the fixes. Helps on CI. ## Test plan 🚀
This was referenced Apr 1, 2025
r0h0gg6
pushed a commit
to r0h0gg6/react-native-reanimated
that referenced
this pull request
Jul 28, 2025
## Summary Since - facebook/react-native#46602 got merged we can apply the fixes. Helps on CI. ## Test plan 🚀
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary:
React Native app template provided by the CLI currently uses
metro-configdirectly forMetroConfigtype.However, it doesn't have
metro-configas neither a dependency or dev dependency, which can lead to version mismatches.While this is obviously a mistake on the template repo side,
metro-configversions aren't matched withreact-nativeversions. Therefore, getting the correct version ofmetro-configfrom@react-native/metro-configwould require reflecting on@react-native/metro-config's package.json etc. which is far from ideal. In my opinion it's would be much better to exposeMetroConfigtype from@react-native/metro-configdirectly.Version mismatching can happen in a monorepo setup. Say we have the monorepo structure using Yarn Modern:
react-native@0.75gets hoisted to the monorepo root whilereact-native@0.76sits in an RN 0.76 app workspace.Say we have the following
RN76-app/metro.config.jscontents:In this case,
require('@react-native/metro-config')would resolve toRN76-app/node_modules/@react-native/node_modules/metro-configsince@react-native/metro-configis a (dev) dependency of the App.However
import('metro-config).MetroConfigwould resolve tonode_modules/metro-configsince it's not a direct dependency.This is how we have a mismatch - imported functions come from different packages than imported type.
Changelog:
[GENERAL] [ADDED] - Expose
MetroConfigtype directly from@react-native/metro-config.Test Plan:
yarn buildto generate dist for@react-native/metro-config, see it has the export ofMetroConfig.Notes
If this PR gets approved, I'll submit relevant one to the CLI template.