Skip to content

Honour Metro's experimentalImportSupport in react-native/babel-preset via the Babel caller - #58459

Open
shubh73 wants to merge 1 commit into
react:mainfrom
shubh73:babel-preset-import-support-caller
Open

Honour Metro's experimentalImportSupport in react-native/babel-preset via the Babel caller#58459
shubh73 wants to merge 1 commit into
react:mainfrom
shubh73:babel-preset-import-support-caller

Conversation

@shubh73

@shubh73 shubh73 commented Sep 10, 2026

Copy link
Copy Markdown

Summary:

experimentalImportSupport: true in a Metro config asks Metro to lower import/export itself, so react-native/babel-preset must leave ESM intact. react-native/metro-babel-transformer only passes the matching disableImportExportTransform preset option when the project has no Babel config of its own. Apps from the template have a babel.config.js naming the preset, so the preset lowers to CommonJS regardless and the Metro option is silently a no-op (react/metro#909). It also keeps default imports eager under inlineRequires, which only inlines bare require calls.

Pass experimentalImportSupport through the Babel caller and resolve it in the preset as options.disableImportExportTransform ?? babel.caller(...) ?? false, the channel #57973 added for inlinePlatform. Preset options still take precedence and the default is unchanged.

Changelog:

[GENERAL] [FIXED] - experimentalImportSupport in a Metro config now takes effect when react-native/babel-preset is named in a project Babel config

Test Plan:

  • yarn test packages/react-native-babel-preset packages/react-native-babel-transformer: 151 pass, including new tests for the caller channel and for a project babel.config.js naming the preset.
  • yarn flow-check: no errors.
  • private/helloworld iOS release bundle with experimentalImportSupport: true and the stock babel.config.js: module-scope _interopRequireDefault(require(...)) 1274 → 0, modules evaluated at startup 83 → 49. Without the option, output is byte-identical.

🤖 Generated with Claude Code

@meta-cla meta-cla Bot added the CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. label Sep 10, 2026
@shubh73
shubh73 force-pushed the babel-preset-import-support-caller branch from 6d4e378 to 3fae730 Compare September 10, 2026 16:49
@facebook-github-tools facebook-github-tools Bot added the Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team. label Sep 10, 2026
@shubh73
shubh73 force-pushed the babel-preset-import-support-caller branch from 3fae730 to bee1ca0 Compare September 10, 2026 16:55
…set` via the Babel caller

`experimentalImportSupport: true` in a Metro config asks Metro to lower `import`/`export` itself, so `react-native/babel-preset` must leave ESM intact. `react-native/metro-babel-transformer` only passes the matching `disableImportExportTransform` preset option when the project has no Babel config of its own. Apps from the template have a `babel.config.js` naming the preset, so the preset lowers to CommonJS regardless and the Metro option is silently a no-op (react/metro#909). It also keeps default imports eager under `inlineRequires`, which only inlines bare `require` calls.

Pass `experimentalImportSupport` through the Babel caller and resolve it in the preset as `options.disableImportExportTransform ?? babel.caller(...) ?? false`, the channel react#57973 added for `inlinePlatform`. Preset options still take precedence and the default is unchanged.

Changelog:
[General][Fixed] - `experimentalImportSupport` in a Metro config now takes effect when `react-native/babel-preset` is named in a project Babel config

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@shubh73
shubh73 force-pushed the babel-preset-import-support-caller branch from bee1ca0 to c306f3f Compare September 10, 2026 16:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CLA Signed This label is managed by the Facebook bot. Authors need to sign the CLA before a PR can be reviewed. Shared with Meta Applied via automation to indicate that an Issue or Pull Request has been shared with the team.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant