fix(metro-resolver): Skip bare ext file resolution on ESM module resolution#1673
Open
kitten wants to merge 1 commit into
Open
fix(metro-resolver): Skip bare ext file resolution on ESM module resolution#1673kitten wants to merge 1 commit into
kitten wants to merge 1 commit into
Conversation
8fd8509 to
4e8f2e6
Compare
4e8f2e6 to
1c69f23
Compare
1c69f23 to
59ae99e
Compare
59ae99e to
36df533
Compare
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
Note
Opening this mostly to ask whether this is intended behaviour, so it's potentially not as polished/finalized as other PRs. Marking from draft as open to run tests though
In CommonJS, it's normal for
metro-resolverto probenode_modules/[moduleName][ext]for implementations. For example, forinvariant, we'd probenode_modules/invariant.js,node_modules/invariant.web.js, etc first, when falling back to file resolution.However, when resolving for an ESM import, this is unwanted, out-of-spec and redundant, and we can skip this resolution, since ESM expects a full
node_modulesstructure rather than the legacy behaviour.While this typically doesn't matter since files in
node_moduleshave become increasingly rare, it can be used to skip redundant file resolution for ESM innode_modules.The legacy behaviour still has to apply to sub-paths, since sub-path imports are otherwise also disabled for sub-paths without
exportsconditions that replace them. However, for the root path case, which is the most common, the added lookups look redundant to me.Arguably, if we want the sub-path extensions behaviour to still apply to ESM we could disable file resolution entirely when
package.json:exportsare present, and instead rely on conditions. However, this would be a "more" breaking change.Changelog: [Fix] Prevent direct file resolution in module paths for ESM
Test plan
Unit tests (LLM-written) have been added to demonstrate the behaviour