-
Notifications
You must be signed in to change notification settings - Fork 29.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Resolution fails on missing exports
array path
#44282
Comments
cc @nodejs/modules |
Duplicate of #37928? Specifically, #37928 (comment) seems to apply here: |
The proposal makes a difference between invalid / not supported entries (those are skipped) and failure to load a resource (which is a straight error). The reason here is that checking for resource existence could be expensive (think network requests etc.) or ambiguous (permissions, redirects, etc.). |
Thanks for explaining @jkrems. That reason makes sense. Would it be worth clarifying the behavior in the docs/proposal? Based on #37928, vitejs/vite#4439, and seeing how both Webpack and TypeScript has implemented them, a lot of people seem to interpret the fallback array as a way to add fallback file paths. It might actually be fine for packages that are designed to be consumed by bundlers (and for their own resolvers to deviate), but it might set an incorrect precedent for Node.js packages, which may be particularly damaging because it throws. |
@unional did you delete your comment here? In the case: {
"exports": [{ "a": { "b": "./b.js" } }, "./c.js"]
}
The array fallbacks are only for syntactical validations - this allows us to add new types of resolution semantics in future that do not start with {
"imports": {
"#newbuiltin": [{
"node": "node:newbuiltin"
}, "./newbuiltin-polyfill.js"]
}
} as a way of supporting new core modules with a fallback. The above might be permissable since it doesn't need to check the file system but can use an internal list. Similarly even for any other types of protocol systems in future. This is all hypothetical though. |
Thanks. Yes I deleted my message because I realized the code does support it correctly. |
Version
v18.7.0
Platform
macOS 12.4
Subsystem
No response
What steps will reproduce the bug?
Import a package with an exports array where the first path doesn't exist. For example:
/node_modules/package/package.json
:/node_modules/package/entry.js
:/index.mjs
:Reproduction using Node.js v16.14.2 on StackBlitz:
https://stackblitz.com/edit/node-52xlzc?file=index.js
How often does it reproduce? Is there a required condition?
Always. No.
What is the expected behavior?
For the resolution error to be ignored and to attempt resolution on the next path.
Based on the proposal spec, I believe that's how fallbacks should work.
What do you see instead?
The resolution fails at the first path.
Additional information
Worth mentioning that the fallback is used when a condition prevents the path from even being attempted:
The text was updated successfully, but these errors were encountered: