Skip to content

Commit e52ba57

Browse files
authored
fix: update tsconfig to align how metro resolves package exports (#701)
This updates the `tsconfig.json` to match metro's behaviour: https://reactnative.dev/blog/2023/06/21/package-exports-support#enabling-package-exports-beta
1 parent 62352f8 commit e52ba57

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

docs/pages/esm.md

+4-3
Original file line numberDiff line numberDiff line change
@@ -18,17 +18,18 @@ You can verify whether ESM support is enabled by checking the configuration for
1818

1919
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.
2020

21-
It's recommended to specify `"moduleResolution": "Bundler"` in your `tsconfig.json` file as well:
21+
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):
2222

2323
```json
2424
{
2525
"compilerOptions": {
26-
"moduleResolution": "Bundler"
26+
"moduleResolution": "Bundler",
27+
"resolvePackageJsonImports": false
2728
}
2829
}
2930
```
3031

31-
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.
32+
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.
3233

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

packages/create-react-native-library/templates/common/tsconfig.json

+1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
"noUnusedLocals": true,
2222
"noUnusedParameters": true,
2323
"resolveJsonModule": true,
24+
"resolvePackageJsonImports": false,
2425
"skipLibCheck": true,
2526
"strict": true,
2627
"target": "ESNext",

0 commit comments

Comments
 (0)