From 459d156d214432e92d47d1663f9f6d5477a891f2 Mon Sep 17 00:00:00 2001 From: Satyajit Sahoo Date: Sun, 8 Sep 2024 19:44:51 +0530 Subject: [PATCH] fix: conditionally generate package.json --- .../react-native-builder-bob/src/utils/compile.ts | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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) => {