diff --git a/babel.config.js b/babel.config.js index 66094c956fac8..7e63e59581e91 100644 --- a/babel.config.js +++ b/babel.config.js @@ -63,7 +63,7 @@ const webpack = { }; const metro = { - presets: [require('@react-native/babel-preset')], + presets: [[require('@react-native/babel-preset'), {disableImportExportTransform: true}]], plugins: [ ['babel-plugin-react-compiler', ReactCompilerConfig], // must run first! @@ -174,5 +174,14 @@ module.exports = (api) => { const runningIn = api.caller((args = {}) => args.name); console.debug(' - running in: ', runningIn); - return ['metro', 'babel-jest'].includes(runningIn) ? metro : webpack; + // Jest runs in Node.js without Metro's experimentalImportSupport transform, + // so Babel must handle import/export transforms for tests. + if (runningIn === 'babel-jest') { + return { + ...metro, + presets: [[require('@react-native/babel-preset'), {disableImportExportTransform: false}]], + }; + } + + return runningIn === 'metro' ? metro : webpack; }; diff --git a/metro.config.js b/metro.config.js index 470cd07af6e64..0f24889b6868c 100644 --- a/metro.config.js +++ b/metro.config.js @@ -35,6 +35,7 @@ const config = { transformer: { getTransformOptions: async () => ({ transform: { + experimentalImportSupport: true, inlineRequires: true, }, }),