-
-
Notifications
You must be signed in to change notification settings - Fork 4k
Description
Which application or package is this feature request for?
brokers, builders, collection, core, formatters, next, proxy, rest, structures, util, voice, ws
Feature
Since all packages seem to now require node >=22.12.0
, I'm proposing dropping the CJS builds for at least the TypeScript packages (not proposing it for discord.js
initally since it doesn't use a bundler and would be more work, likely affecting every file). Node 22.12.0
unflagged support for require
ing ESM, which is currently in a release candidate status with plans to make it stable quite soon. Currently all relevant TypeScript packages ship two versions of the same library, one in CJS and the other in ESM. This isn't ideal not just because it makes installations 2x larger, it also makes those packages vulnerable to the dual package hazard. I see zero drawbacks to dropping CJS builds considering nothing would change for users and they would still be able to use the library the same way as always, even if they use CJS.
Ideal solution or implementation
Considering tsup
is used, this should be as easy as dropping 'cjs'
from the format array in the config file, and changing every applicable package.json
.
Alternative solutions or implementations
If for some strange reason it is decided to keep CJS builds despite the fact that users using the minimum required node version can require(esm)
with absolutely no issues, at the very least the module-sync
export condition could be used to avoid the dual package hazard.
"module-sync"
- matches no matter the package is loaded viaimport
,import()
orrequire()
. The format is expected to be ES modules that does not contain top-level await in its module graph - if it does,ERR_REQUIRE_ASYNC_MODULE
will be thrown when the module isrequire()
-ed.
Other context
I have a PR basically ready but I would like to first ask for clarification of which packages should be moved to ESM before submitting, especially around internal packages.