Skip to content

Commit 2909dfd

Browse files
committed
doc: document subpath-pattern precedence and null blocking in exports
The exports resolution sorts subpath patterns by specificity (lib/internal/modules/esm/resolve.js patternKeyCompare), so the pattern with the longest matching prefix wins regardless of declaration order. A null target blocks any subpath matching its pattern, regardless of key position. The documentation did not state either rule, so add a short clarification after the existing null example. Fixes: #44517
1 parent 26079c0 commit 2909dfd

1 file changed

Lines changed: 9 additions & 0 deletions

File tree

doc/api/packages.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,15 @@ import featureX from 'es-module-package/features/x.js';
655655
// Loads ./node_modules/es-module-package/src/features/x.js
656656
```
657657

658+
When a subpath matches more than one pattern, the pattern with the longest
659+
matching prefix (the most specific pattern) takes precedence, regardless of the
660+
order in which the patterns are declared in the `exports` object.
661+
662+
A `null` target blocks access to the subpaths that would otherwise match its
663+
pattern: requesting such a subpath throws
664+
[`ERR_PACKAGE_PATH_NOT_EXPORTED`][] regardless of where the `null` pattern is
665+
positioned among the keys.
666+
658667
### Conditional exports
659668

660669
<!-- YAML

0 commit comments

Comments
 (0)