Closed bjornharrtell closed 3 years ago
Per https://github.com/rollup/plugins/tree/master/packages/node-resolve#package-entrypoints
This plugin supports the package entrypoints feature from node js, specified in the exports or imports field of a package. Check the official documentation for more information on how this works. This is the default behavior. In the abscence of these fields, the fields in mainFields will be the ones to be used.
Since we have added the exports
field (to allow native ESM), this now means that mainFields
can no longer override the default behavior (though keep reading).
However, and something this blurb probably ought to mention, one can use the exportConditions
option array to indicate that one wishes to match other items within the exports
object. So if you add exportConditions: ['browser']
or exportConditions: ['umd']
, you can get those added.
FWIW, it seems that when the plugin iterates over the exports
, it does so in key order, and with the conditions
in that block of code coming from code defined originally here. That code uses exportsConditions
, but only as a fallback to the items in these arrays, meaning that 'default' and 'module' will always be checked, and also either import
or if require resolution is enabled (though the latter is, I think, only triggerable by the likes of other Rollup plugins such as commonjs).
The exportConditions docs explain this in stating, "Setting this option will add extra conditions on top of the default conditions", but I have elaborated in case that statement was not clear.
But I don't expect the fact that certain ones are defined by default should be a problem since our exports
object, at least inside .
defines the browser
and umd
entries before import
, so I expect you should be able to get at either of those first if you include them. Let us know if setting exportConditions: ['browser']
works for you.
@brettz9 indeed exportConditions: ['browser']
works. Thanks!
No matter what I try with
@rollup/plugin-node-resolve
(i.e{ mainFields: ['browser', 'module', 'main'] })
) it seems ineffective and it pulls in/node_modules/jsonpath-plus/dist/index-node-esm.mjs
causing missingvm
dependency.