You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/pages/esm.md
+5-4Lines changed: 5 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -20,13 +20,12 @@ The `"esm": true` option enables ESM-compatible output by adding the `.js` exten
20
20
21
21
For TypeScript, it also generates 2 sets of type definitions if the [`commonjs`](build.md#commonjs) target is also enabled: one for the CommonJS build and one for the ES module build.
22
22
23
-
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):
23
+
It's recommended to specify `"moduleResolution": "bundler"` in your `tsconfig.json` file to match Metro's behavior:
24
24
25
25
```json
26
26
{
27
27
"compilerOptions": {
28
-
"moduleResolution": "bundler",
29
-
"resolvePackageJsonImports": false
28
+
"moduleResolution": "bundler"
30
29
}
31
30
}
32
31
```
@@ -53,7 +52,7 @@ To make use of the output files, ensure that your `package.json` file contains t
53
52
},
54
53
```
55
54
56
-
The `main` field is for tools that don't support the `exports` field (e.g. [Metro](https://metrobundler.dev/)). The `module` field is a non-standard field that some tools use to determine the ESM entry point.
55
+
The `main` field is for tools that don't support the `exports` field (e.g. [Jest](https://jestjs.io)). The `module` field is a non-standard field that some tools use to determine the ESM entry point.
57
56
58
57
The `exports` field is used by Node.js 12+, modern browsers and tools to determine the correct entry point. The entrypoint is specified in the `.` key and will be used when the library is imported or required directly (e.g. `import 'my-library'` or `require('my-library')`).
59
58
@@ -71,6 +70,8 @@ You can also specify additional conditions for different scenarios, such as `rea
71
70
72
71
The `./package.json` field is used to point to the library's `package.json` file. It's necessary for tools that may need to read the `package.json` file directly (e.g. [React Native Codegen](https://reactnative.dev/docs/the-new-architecture/what-is-codegen)).
73
72
73
+
> Note: Metro enables support for `package.json` exports by default from version [0.82.0](https://github.com/facebook/metro/releases/tag/v0.82.0). In previous versions, experimental support can be enabled by setting the `unstable_enablePackageExports` option to `true` in the [Metro configuration](https://metrobundler.dev/docs/configuration/). If this is not enabled, Metro will use the entrypoint specified in the `main` field.
74
+
74
75
## Guidelines
75
76
76
77
There are still a few things to keep in mind if you want your library to be ESM-compatible:
0 commit comments