diff --git a/packages/react-native-builder-bob/src/utils/compile.ts b/packages/react-native-builder-bob/src/utils/compile.ts index 42fcca7b6..c0afdf8e5 100644 --- a/packages/react-native-builder-bob/src/utils/compile.ts +++ b/packages/react-native-builder-bob/src/utils/compile.ts @@ -68,11 +68,16 @@ export default async function compile({ } await fs.mkdirp(output); - await fs.writeJSON(path.join(output, 'package.json'), { - // Treat code with ESM syntax as CommonJS if `esm` is not enabled + + if (!esm) { + // Ideally we should code with ESM syntax as CommonJS if `esm` is not enabled // This maintain compatibility with code written for CommonJS - type: modules === 'commonjs' || !esm ? 'commonjs' : 'module', - }); + // However currently NextJS has non-standard behavior and breaks this + // So for now we only set this conditionally + await fs.writeJSON(path.join(output, 'package.json'), { + type: modules === 'commonjs' ? 'commonjs' : 'module', + }); + } await Promise.all( files.map(async (filepath) => {