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 }}
This repository has been archived by the owner on Aug 13, 2022. It is now read-only.
Node.js 12+ with ESM support means that based on the upstream import, different files can be imported at runtime. We should have a good test / set of tests around this scenario. Offhand, maybe:
Code
Extensions: Make sure the core library handles .cjs and .mjs extensions for importing and filtering.
Mode Choices: There are really 3 options -- old CJS (that doesn't consider exports), new CJS (that does consider exports), and new ESM. Possible tokens: NODE_CJS_OLD, NODE_CJS_NEW, NODE_ESM ( This looks tough... )
Bundle all export conditions: ( Current approach ) Find all reasonable Node.js conditions (import, require, node, development, production) and package them all. Trade off size for correctness.
"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.
The text was updated successfully, but these errors were encountered:
Node.js 12+ with ESM support means that based on the upstream import, different files can be imported at runtime. We should have a good test / set of tests around this scenario. Offhand, maybe:
Code
.cjs
and.mjs
extensions for importing and filtering.Mode Choices: There are really 3 options -- old CJS (that doesn't consider( This looks tough... )exports
), new CJS (that does considerexports
), and new ESM. Possible tokens:NODE_CJS_OLD
,NODE_CJS_NEW
,NODE_ESM
import
,require
,node
,development
,production
) and package them all. Trade off size for correctness.Research
resolve
package has big open ticket on ESM resolution: Support ESM resolution browserify/resolve#222Tests
See https://nodejs.org/api/packages.html#packages_determining_module_system for more details.
Scenario
es-get-iterator
From https://unpkg.com/browse/es-get-iterator@1.1.2/ this is the behavior:
./index.js
offpackage.json:main
.exports
field with.
entry resolving to./node.js
exports
field with.
entry resolving to./node.mjs
Notes
Conditions
From https://nodejs.org/api/packages.html#packages_conditional_exports
The text was updated successfully, but these errors were encountered: