Skip to content

Commit 85675aa

Browse files
committed
chore: add sample snippet to configure main fields for module resolution algorithm
1 parent 054fa33 commit 85675aa

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

website/versioned_docs/version-30.0/Configuration.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,6 +1529,20 @@ const config: Config = {
15291529
export default config;
15301530
```
15311531

1532+
Based on the fact that `jest-resolve` uses `unrs-resolver` and passes additional options to it, we can modify the configuration of `mainFields`. For example, for React Native projects, you might use this config:
1533+
1534+
```js
1535+
module.exports = (path, options) => {
1536+
// Call the defaultResolver, so we leverage its cache, error handling, etc.
1537+
return options.defaultResolver(path, {
1538+
...options,
1539+
// This is option from unrs-resolver from https://github.com/unrs/unrs-resolver?tab=readme-ov-file#main-field
1540+
// We use the fact that jest-resolve just passes extra options to unrs-resolver
1541+
mainFields: ['react-native', 'main'],
1542+
});
1543+
};
1544+
```
1545+
15321546
### `restoreMocks` \[boolean]
15331547

15341548
Default: `false`

0 commit comments

Comments
 (0)