[enhanced-resolve] imports field: internal intentional feature or spec deviation? #20684
stormslowly
started this conversation in
General
Replies: 2 comments
-
|
@stormslowly Hello, looks like it is a spec deviation, |
Beta Was this translation helpful? Give feedback.
0 replies
-
|
Thanks for the feedback — fix in PR webpack/enhanced-resolve#503 |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi! I'm working on rspack-resolver, a Rust port that aims to align with enhanced-resolve's behavior. While syncing features, we noticed a behavior difference between enhanced-resolve and Node.js in how the
importsfield handles non-relative targets (bare specifiers).The Difference
In
ImportsFieldPlugin.js, after resolving theimportsfield mapping, non-relative targets (those not starting with.) are sent to theinternal-resolvehook:The
internal-resolvehook re-enters the full resolver pipeline (parsed-resolve→described-resolve→raw-resolve→normal-resolve→ ...), which includes theinternalhook that processes#-prefixed specifiers again.In contrast, the Node.js spec uses
PACKAGE_RESOLVE(target, packageURL + "/")inPACKAGE_TARGET_RESOLVEstep 1.2, which only resolves bare package names vianode_moduleslookup and does not re-enter imports resolution.{ "imports": { "#a": "#b", "#b": "./the.js" } }resolve("#a")resolve("#b")MODULE_NOT_FOUND./the.js./the.js./the.jsNotFound./the.jsNode.js fails on
#abecausePACKAGE_RESOLVE("#b", ...)tries to find a package named#binnode_modules, which doesn't exist. enhanced-resolve succeeds becauseinternal-resolvefeeds#bback through the full pipeline, hitting theinternalhook →ImportsFieldPluginagain, resolving the chain.For standard bare specifiers (e.g.,
"#c": "c"), all three resolvers agree —"c"resolves tonode_modules/c/index.jsregardless of the mechanism used.Question
Is the use of
internal-resolve(instead ofPACKAGE_RESOLVE) an intentional enhanced feature of enhanced-resolve? Or is it an unintended spec deviation?Understanding this would help us decide the correct behavior for rspack-resolver — whether we should replicate
internal-resolvesemantics for full compatibility with enhanced-resolve/webpack, or stick with Node.js spec behavior.Thank you for your time!
Beta Was this translation helpful? Give feedback.
All reactions