-
-
Notifications
You must be signed in to change notification settings - Fork 594
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
node-resolve: “browser” field not being used for sub imports in dependencies #781
Comments
Rollup works in the browser and in node, so it cant add the browser condition by default mode. Using the order of the keys in the pkg json is how node js specced this, we are following that. Otherwise this becomes inconsistent between tools. |
It doesn’t add the browser condition on { browser: true } though. I use rollup for Node.js compiles so yes, please don’t make this default, but it should resolve sub imports from export maps without adding exportConditions. Can you point me to the spec that says browser field is secondary when placed later in the map? This is a real problem for systems that produce deterministic maps so I’ll need to go over there and explain this issue. |
That's true... the The full resolve algorithm is here: https://nodejs.org/dist/latest-v15.x/docs/api/esm.html#esm_resolver_algorithm_specification |
Ran into this too. The same
Both were setup for Node.js by default, but both also have |
Same problem when using https://www.npmjs.com/package/uuid and trying to build a package for nodejs env. Apparently, this plugin pulls code for |
The module version of yargs causes unresolved named export errors with rollup node-resolve, potentially related to rollup/plugins#781
With #866, when setting In a subsequent fix the conditions were matched based on object order as well so this should be working correctly now. Please post a new issue if there are any further inconsistencies, but I believe we should be to spec now. |
This can’t be reproduced using the above guidelines because it requires a dependency be installed via Node.js that is importing a sub export in an export map that has both “import” and “browser” fields.
The issue is simple to explain. I have a dependency installed that is written in native ESM. One of the exports in the export
map has an
import
and abrowser
field. If the plugin applied the same logic as themain
field then I would get back thebrowser
entrypoint w/{ browser: true }
configured. But I don’t, I get back theimport
target which is intended for Node.js.I’ve tracked the issue all the way down and it’s here https://github.com/rollup/plugins/blob/master/packages/node-resolve/src/package/resolvePackageTarget.js#L88-L105
A few problems:
“browser” is never added by this plugin to
context.conditions
. I can work around this locally by adding a config setting of{ exportConditions: [ “browser” ] }
but that still leaves me with the second problem.This resolution logic is applied in the order it is defined in
package.json
rather than the order defined by the conditions. This is really not what you want, you want to configure the preferred ordering in the compiler and treat the export map as unordered. It’s just generally a bad idea to rely on map ordering.While I can tell you for certain that this is where the bug is, I’m not sure this is where you want to fix it. This module is rather complicated and there’s a lot of
userBrowserOverride
logic in other places that just isn’t applied when you’re importing something other than the main field.Expected Behavior
Read above.
Actual Behavior
Read above.
Additional Information
This complicated issue template is a big barrier to entry for logging issues.
The text was updated successfully, but these errors were encountered: