Skip to content

Commit 2493fe1

Browse files
committed
fix: fix generating package.json when esm is enabled
1 parent 09e8647 commit 2493fe1

File tree

1 file changed

+7
-5
lines changed
  • packages/react-native-builder-bob/src/utils

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,11 +71,13 @@ export default async function compile({
7171

7272
await fs.mkdirp(output);
7373

74-
if (!esm) {
75-
// Ideally we should code with ESM syntax as CommonJS if `esm` is not enabled
76-
// This maintain compatibility with code written for CommonJS
77-
// However currently NextJS has non-standard behavior and breaks this
78-
// So for now we only set this conditionally
74+
// Imports are not rewritten to include the extension if `esm` is not enabled
75+
// Ideally we should always treat ESM syntax as CommonJS if `esm` is not enabled
76+
// This would maintain compatibility for legacy setups where `import`/`export` didn't require file extensions
77+
// However NextJS has non-standard behavior and breaks if we add `type: 'commonjs'` for code with import/export
78+
// So we skip generating `package.json` if `esm` is not enabled and `modules` is not `commonjs`
79+
// This means that user can't use `type: 'module'` in root `package.json` without enabling `esm` for `module` target
80+
if (esm || modules === 'commonjs') {
7981
await fs.writeJSON(path.join(output, 'package.json'), {
8082
type: modules === 'commonjs' ? 'commonjs' : 'module',
8183
});

0 commit comments

Comments
 (0)