Skip to content

Commit 459d156

Browse files
committed
fix: conditionally generate package.json
1 parent 9e9e1fb commit 459d156

File tree

1 file changed

+9
-4
lines changed
  • packages/react-native-builder-bob/src/utils

1 file changed

+9
-4
lines changed

packages/react-native-builder-bob/src/utils/compile.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,11 +68,16 @@ export default async function compile({
6868
}
6969

7070
await fs.mkdirp(output);
71-
await fs.writeJSON(path.join(output, 'package.json'), {
72-
// Treat code with ESM syntax as CommonJS if `esm` is not enabled
71+
72+
if (!esm) {
73+
// Ideally we should code with ESM syntax as CommonJS if `esm` is not enabled
7374
// This maintain compatibility with code written for CommonJS
74-
type: modules === 'commonjs' || !esm ? 'commonjs' : 'module',
75-
});
75+
// However currently NextJS has non-standard behavior and breaks this
76+
// So for now we only set this conditionally
77+
await fs.writeJSON(path.join(output, 'package.json'), {
78+
type: modules === 'commonjs' ? 'commonjs' : 'module',
79+
});
80+
}
7681

7782
await Promise.all(
7883
files.map(async (filepath) => {

0 commit comments

Comments
 (0)