Fix exact "exports" and "imports" keys with no target falling back to a pattern - #1987
Merged
robhogan merged 3 commits intoSep 27, 2026
Merged
Conversation
… a pattern matchSubpathFromExportsLike only tried subpath patterns when the exact key lookup returned null, so an exact key whose value is null, or a conditions object with no matching condition, fell through to a less specific pattern such as "./*". Node.js only tries patterns when there is no exact key, and reports these subpaths as not exported. Check whether the exact key exists instead of whether its target is null.
Covers the "exports" side of the fix: an exact key with a null target, and one with no matching condition, alongside a "./*" pattern. Both now warn and fall back to file-based resolution instead of resolving through the pattern.
robhogan
reviewed
Sep 27, 2026
kwy404
added a commit
to kwy404/kwy404
that referenced
this pull request
Sep 27, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
matchSubpathFromExportsLike, used for both"exports"and"imports", looks up the exact subpath key first and only tries subpath patterns when there is no exact match. But it detects "no exact match" withtarget == null, so an exact key that exists but has no target is treated like a missing key. That happens when the value isnull, or when it is a conditions object with no matching condition and nodefault(reduceExportsLikeMapreduces that tonull). Metro then goes on to match a less specific pattern.With this package:
test-pkg/internalandtest-pkg/serverresolve tolib/internal.jsandlib/server.jsthrough./*, with no warning. Node.js only tries patterns when there is no exact key, so it throwsERR_PACKAGE_PATH_NOT_EXPORTEDfor both. For the same shape in"imports"it throwsERR_PACKAGE_IMPORT_NOT_DEFINED(checked withrequire.resolveon Node 24.16). Metro already handles null pattern keys this way.The fix checks whether the exact key exists (
has) instead of whether its target is null. These subpaths are now reported as not exported or not resolved, with the usual warning and file-based fallback.Changelog: [Fix] An exact "exports" or "imports" subpath with a null or unmatched target no longer resolves through a less specific subpath pattern
Test plan
Added a test to
packages/metro-resolver/src/__tests__/package-imports-test.js. It uses"#features/*"plus an exact"#features/foo": nulland an exact"#features/bar": {"browser": ...}.#features/fooand#features/barresolve tosrc/features/foo.jsandsrc/features/bar.jsthrough the pattern.yarn jest packages/metro-resolverpasses.scripts/jestFilter.jsskipspackage-exports-test.jsand most other resolver suites on Windows, so I also ran all 8 resolver suites with the Windows test fixes from Fix Windows-incompatible Jest tests #1937 applied locally: 125 tests passed. There, the"exports"example above resolved tolib/internal.jsandlib/server.jsbefore the fix, and to the warning plus the file-based fallback after it.flow focus-check,eslintandprettier --checkon both changed files: clean.