Open joyeecheung opened 12 hours ago
From a simple glance of the packages, it seems they mostly have "type": "module"
but also a "require"
exports pointing to a CJS version (typically, .cjs
, as they probably want to use .js
for ESM), thus being actually dual.
Hi again! 👋
Ah, yeah. I guess, when making this initially, the idea was more to track ESM. Not dual. ESM being the “highest to achieve”. So indeed, if "type": "module",
is seen, that’s enough to classify it as ESM.
Here’s an example from: @humanwhocodes/retry
:
2 "name": "@humanwhocodes/retry",
3 "version": "0.3.0",
4 "description": "A utility to retry failed async methods.",
5 "type": "module",
6 "main": "dist/retrier.cjs",
7 "module": "dist/retrier.js",
8 "types": "dist/retrier.d.ts",
9 "exports": {
10 "require": {
11 "types": "./dist/retrier.d.cts",
12 "default": "./dist/retrier.cjs"
13 },
14 "import": {
15 "types": "./dist/retrier.d.ts",
16 "default": "./dist/retrier.js"
17 }
18 },
Looking at my code, my above assumption may not be true:
New theory: perhaps it’s the nested conditions? 🤷♂️
Yeah I think when the exports conditions contain require
as a key (either nested, or not), it's likely to be dual.
Ah, yeah. I guess, when making this initially, the idea was more to track ESM. Not dual. ESM being the “highest to achieve”.
Got it - I think the difference is between "shipping ESM" v.s. "authoring in ESM". Technically the ones that are labeled as "esm"/"faux"/"dual" are probably all authored in ESM, but differ in whether they ship themselves as ESM-only. "type": "module"
is a good indicator that the module is authored in ESM, but not necessarily for the way the module is shipped.
When I was testing out https://github.com/nodejs/node/pull/55085/, to get a sense of what modules couldn't be loaded before
require(esm)
is supported but could be loaded after it's unflagged, I have this script to test loading some high-impact packages locally usingrequire()
, and it seems out of 662 packages labeled asesm
, 103 could already be loaded byrequire()
even withoutrequire(esm)
, so they are probably dual.Here is the list I've found: