Skip to content

Commit

Permalink
fix: update tsconfig to align how metro resolves package exports (#701)
Browse files Browse the repository at this point in the history
  • Loading branch information
satya164 authored Dec 4, 2024
1 parent 62352f8 commit e52ba57
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 3 deletions.
7 changes: 4 additions & 3 deletions docs/pages/esm.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,18 @@ You can verify whether ESM support is enabled by checking the configuration for

The `"esm": true` option enables ESM-compatible output by adding the `.js` extension to the import statements in the generated files. For TypeScript, it also generates 2 sets of type definitions: one for the CommonJS build and one for the ES module build.

It's recommended to specify `"moduleResolution": "Bundler"` in your `tsconfig.json` file as well:
It's recommended to specify `"moduleResolution": "Bundler"` and `"resolvePackageJsonImports": false` in your `tsconfig.json` file to match [Metro's behavior](https://reactnative.dev/blog/2023/06/21/package-exports-support#enabling-package-exports-beta):

```json
{
"compilerOptions": {
"moduleResolution": "Bundler"
"moduleResolution": "Bundler",
"resolvePackageJsonImports": false
}
}
```

This means that you don't need to specify the file extension in the import statements. They'll be automatically added when possible during the build process.
Specifying `"moduleResolution": "Bundler"` means that you don't need to use file extensions in the import statements. Bob automatically adds them when possible during the build process.

To make use of the output files, ensure that your `package.json` file contains the following fields:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
"noUnusedLocals": true,
"noUnusedParameters": true,
"resolveJsonModule": true,
"resolvePackageJsonImports": false,
"skipLibCheck": true,
"strict": true,
"target": "ESNext",
Expand Down

0 comments on commit e52ba57

Please sign in to comment.