mirror of
https://github.com/react/react-native.git
synced 2026-09-28 05:13:06 +08:00
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 (https://github.com/facebook/metro/issues/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 https://github.com/react/react-native/issues/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 Pull Request resolved: https://github.com/react/react-native/pull/58459 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](https://claude.com/claude-code) Reviewed By: javache Differential Revision: D120118487 Pulled By: vzaidman fbshipit-source-id: 23eddc3f235cb6455c51ce6cd3a14f1123943cde
@react-native/metro-babel-transformer
Metro Babel transformer for React Native applications. Applies @react-native/babel-preset when transforming source files during bundling.