Skip to content

Commit 5b45554

Browse files
authored
fix: always create package.json with type regardless of esm option (#598)
This will provide more flexibilty to library authors such as specifying `type: module` in their project's `package.json` without breaking the commonjs output for the published code.
1 parent a95d0de commit 5b45554

File tree

2 files changed

+5
-11
lines changed

2 files changed

+5
-11
lines changed

docs/pages/esm.md

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,9 @@ You can verify whether ESM support is enabled by checking the configuration for
1616
}
1717
```
1818

19-
The `"esm": true` option enables ESM-compatible output. Here's what it does:
19+
The `"esm": true` option enables ESM-compatible output by adding the `.js` extension to the import statements in the generated files.
2020

21-
- It adds the `.js` extension to the import statements in the generated files.
22-
- It creates a `package.json` file in the output directory with the content: `{ "type": "module" }`
23-
24-
In addition, it's necessary to specify `"moduleResolution": "Bundler"` in your `tsconfig.json` file:
21+
It's recommended to specify `"moduleResolution": "Bundler"` in your `tsconfig.json` file as well:
2522

2623
```json
2724
{

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

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

7070
await fs.mkdirp(output);
71-
72-
if (esm) {
73-
await fs.writeJSON(path.join(output, 'package.json'), {
74-
type: modules === 'commonjs' ? 'commonjs' : 'module',
75-
});
76-
}
71+
await fs.writeJSON(path.join(output, 'package.json'), {
72+
type: modules === 'commonjs' ? 'commonjs' : 'module',
73+
});
7774

7875
await Promise.all(
7976
files.map(async (filepath) => {

0 commit comments

Comments
 (0)