You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Support pkg.exports.node field when building for Node.js #695
In the examples mentioned, I do not see the node condition specified explicitly. If you read the plugin documentation, you will see that the only conditions set by default are ['default', 'module', 'import']. I am not sure whether the absence of browser should automatically imply node, especially since browser is to my knowledge not yet integrated into package.exports resolution anyway (you would still need to specify the browser condition explicitly). That being said, there is definitely room for improvement, at the very least on documentation level but also to make things clearer for the user with less screws to turn.
@shellscape thanks for the pointer. I must have missed that issue when searching before raising this report. After reading through it I'm still unsure if it really solves this issue out of the box.
Node.js supports the following conditions out of the box:
"import" - matches when the package is loaded via import or import(), or via any top-level import or resolve operation by the ECMAScript module loader. Applies regardless of the module format of the target file. Always mutually exclusive with "require".
"require" - matches when the package is loaded via require(). The referenced file should be loadable with require() although the condition matches regardless of the module format of the target file. Expected formats include CommonJS, JSON, and native addons but not ES modules as require() doesn't support them. Always mutually exclusive with "import".
"node" - matches for any Node.js environment. Can be a CommonJS or ES module file. This condition should always come after "import" or "require".
"default" - the generic fallback that always matches. Can be a CommonJS or ES module file. This condition should always come last.
somewhat suggests that the resulting bundle is supposed to run in Node.js. That's why I made the assumption that when bundling for CJS I would automatically get the Node.js-style package.exports resolution. But maybe I'm misinterpreting things here a bit.
I do agree that browser: false can probably not automatically mean node: true…
So maybe now that package.exports support arrived in the node-resolve plugin it's now also time for a target: option for the node-resolve plugin, similar to what webpack does? Otherwise I see a lot of potential for confusion around this topic.
Definitely, and no matter how we go from here, there should be clear examples in the documentation that show-case the main use-cases (i.e. bundling for Node and bundling for the web).
Reacted by Christoph Tavan, Josh Junon and Hamish Macpherson
@shellscape I've updated the Replit to use @rollup/plugin-node-resolve@11.2.1 but the issue is still there.
If I try to execute the resulting bundle with Node.js I get:
$ node output/bundle.js
\/home/runner/rollup-plugin-repro/output/bundle.js:12
throw new Error('crypto.getRandomValues() not supported. See https://github.com/uuidjs/uuid#getrandomvalues-not-supported');
^
Rollup still seems to pick up the browser build instead of the node build.
This can now be configured when using the exportsConditions: ['node'] option of plugin-node-resolve. If there are any further issues here please do let us know though.
Activity
shellscape commentedon Dec 8, 2020
Have you seen #693?
lukastaegert commentedon Dec 8, 2020
In the examples mentioned, I do not see the
nodecondition specified explicitly. If you read the plugin documentation, you will see that the only conditions set by default are['default', 'module', 'import']. I am not sure whether the absence ofbrowsershould automatically implynode, especially sincebrowseris to my knowledge not yet integrated intopackage.exportsresolution anyway (you would still need to specify thebrowsercondition explicitly). That being said, there is definitely room for improvement, at the very least on documentation level but also to make things clearer for the user with less screws to turn.ctavan commentedon Dec 8, 2020
@shellscape thanks for the pointer. I must have missed that issue when searching before raising this report. After reading through it I'm still unsure if it really solves this issue out of the box.
@lukastaegert I was referring to
a) The node.js documentation at https://nodejs.org/api/packages.html#packages_conditional_exports which states:
Node.js supports the following conditions out of the box:
b) The Webpack documentation at https://webpack.js.org/guides/package-exports/#target-environment which states:
Now when looking at https://rollupjs.org/guide/en/#quick-start the example "For Node.js"
somewhat suggests that the resulting bundle is supposed to run in Node.js. That's why I made the assumption that when bundling for CJS I would automatically get the Node.js-style
package.exportsresolution. But maybe I'm misinterpreting things here a bit.I do agree that
browser: falsecan probably not automatically meannode: true…So maybe now that
package.exportssupport arrived in thenode-resolveplugin it's now also time for atarget:option for thenode-resolveplugin, similar to what webpack does? Otherwise I see a lot of potential for confusion around this topic.lukastaegert commentedon Dec 8, 2020
Definitely, and no matter how we go from here, there should be clear examples in the documentation that show-case the main use-cases (i.e. bundling for Node and bundling for the web).
shellscape commentedon Feb 1, 2021
@ctavan can you double check this against the latest version?
ctavan commentedon Apr 2, 2021
@shellscape I've updated the Replit to use
@rollup/plugin-node-resolve@11.2.1but the issue is still there.If I try to execute the resulting bundle with Node.js I get:
Rollup still seems to pick up the browser build instead of the node build.
guybedford commentedon Apr 30, 2021
This can now be configured when using the
exportsConditions: ['node']option of plugin-node-resolve. If there are any further issues here please do let us know though.ctavan commentedon May 15, 2021
I have configuredexportsConditions: ['node']instead ofbrowser: falsein https://replit.com/@ctavan/rollup-plugin-repro#rollup.config.js but rollup still seems to pick up the browser bundle fromuuid.What am I doing wrong?FTR: I realized it must read
exportConditions: ['node']instead ofexportsConditions: ['node'](there was an "s" too much). It now works! Thank you!