diff --git a/packages/react-native-builder-bob/babel-config.js b/packages/react-native-builder-bob/babel-config.js index 876849e1..7edc1ba8 100644 --- a/packages/react-native-builder-bob/babel-config.js +++ b/packages/react-native-builder-bob/babel-config.js @@ -61,7 +61,16 @@ const getConfig = (defaultConfig, { root, pkg }) => { }, { include: path.join(root, src), - presets: [require.resolve('./babel-preset')], + presets: [ + [ + require.resolve('./babel-preset'), + { + // Let the app's preset handle the commonjs transform + // Otherwise this causes `export` statements in wrong places causing syntax error + supportsStaticESM: true, + }, + ], + ], }, ], }; diff --git a/packages/react-native-builder-bob/babel-preset.js b/packages/react-native-builder-bob/babel-preset.js index 4a239d94..8579cc87 100644 --- a/packages/react-native-builder-bob/babel-preset.js +++ b/packages/react-native-builder-bob/babel-preset.js @@ -4,10 +4,16 @@ const browserslist = require('browserslist'); /** * Babel preset for React Native Builder Bob + * + * @param {Boolean} options.supportsStaticESM - Whether to preserve ESM imports/exports, defaults to `false` + * @param {Boolean} options.rewriteImportExtensions - Whether to rewrite import extensions to '.js', defaults to `false` + * @param {'automatic' | 'classic'} options.jsxRuntime - Which JSX runtime to use, defaults to 'automatic' */ module.exports = function (api, options, cwd) { const opt = (name) => - api.caller((caller) => (caller != null ? caller[name] : undefined)); + options[name] !== undefined + ? options[name] + : api.caller((caller) => (caller != null ? caller[name] : undefined)); const supportsStaticESM = opt('supportsStaticESM'); const rewriteImportExtensions = opt('rewriteImportExtensions');