Skip to content

Commit

Permalink
fix: conditionally generate package.json
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 committed Sep 8, 2024
1 parent 9e9e1fb commit 459d156
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions packages/react-native-builder-bob/src/utils/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand Down

0 comments on commit 459d156

Please sign in to comment.