Skip to content

Commit b029db9

Browse files
committed
fix: fix syntax error when running the app
with latest rn, running the app results in an error: `export declaration must be at top level of module`
1 parent 86c5c67 commit b029db9

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

packages/react-native-builder-bob/babel-config.js

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,16 @@ const getConfig = (defaultConfig, { root, pkg }) => {
6161
},
6262
{
6363
include: path.join(root, src),
64-
presets: [require.resolve('./babel-preset')],
64+
presets: [
65+
[
66+
require.resolve('./babel-preset'),
67+
{
68+
// Let the app's preset handle the commonjs transform
69+
// Otherwise this causes `export` statements in wrong places causing syntax error
70+
supportsStaticESM: true,
71+
},
72+
],
73+
],
6574
},
6675
],
6776
};

packages/react-native-builder-bob/babel-preset.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,16 @@ const browserslist = require('browserslist');
44

55
/**
66
* Babel preset for React Native Builder Bob
7+
*
8+
* @param {Boolean} options.supportsStaticESM - Whether to preserve ESM imports/exports, defaults to `false`
9+
* @param {Boolean} options.rewriteImportExtensions - Whether to rewrite import extensions to '.js', defaults to `false`
10+
* @param {'automatic' | 'classic'} options.jsxRuntime - Which JSX runtime to use, defaults to 'automatic'
711
*/
812
module.exports = function (api, options, cwd) {
913
const opt = (name) =>
10-
api.caller((caller) => (caller != null ? caller[name] : undefined));
14+
options[name] !== undefined
15+
? options[name]
16+
: api.caller((caller) => (caller != null ? caller[name] : undefined));
1117

1218
const supportsStaticESM = opt('supportsStaticESM');
1319
const rewriteImportExtensions = opt('rewriteImportExtensions');

0 commit comments

Comments
 (0)