Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions docs/pages/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,9 @@ You can verify whether ESM support is enabled by checking the configuration for
}
```

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

- It adds the `.js` extension to the import statements in the generated files.
- It creates a `package.json` file in the output directory with the content: `{ "type": "module" }`

In addition, it's necessary to specify `"moduleResolution": "Bundler"` in your `tsconfig.json` file:
It's recommended to specify `"moduleResolution": "Bundler"` in your `tsconfig.json` file as well:

```json
{
Expand Down
9 changes: 3 additions & 6 deletions packages/react-native-builder-bob/src/utils/compile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,9 @@ export default async function compile({
}

await fs.mkdirp(output);

if (esm) {
await fs.writeJSON(path.join(output, 'package.json'), {
type: modules === 'commonjs' ? 'commonjs' : 'module',
});
}
await fs.writeJSON(path.join(output, 'package.json'), {
type: modules === 'commonjs' ? 'commonjs' : 'module',
});

await Promise.all(
files.map(async (filepath) => {
Expand Down