Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hi, team 🙌
I would like to propose a compilation of index.js to make the project compatible with
CommonJS
, without changing the code or the supported versions (e.g, Node.jsv18
).Why?
From Node.js
v23
, an experimental feature (support for loading ES Module in require()
) has been added, which brings up the following error for any command executed from npm:npm ls
,npm i
ornpm view npm version
, for example.The changes
The real changes were made to the package.json, where the new index.cjs file was automatically generated by the
npm run build:cjs
script (I used esbuild because it's dependency-free — it could be any compiler).From a certain point of view, this PR could also be considered as a fix rather than a feature:
fix: support for Node.js v23 without experimental resources
Important
As there is no workflow that automates publishing, it's important to note that the compilation of index.cjs is done manually.
If we create a workflow to automate the publication, the index.cjs would become dispensable from the commit and could be compiled during the CI (which is my personal preference).
Note
I noticed that 4 tests were failing, but I didn't touch them or the main file (index.js).
It would be a pleasure to help with the correction of these tests if necessary.
Related
support-color
usingrequire()
:CC!@sindresorhus, @Qix-, @ljharb, @mantoni (and all the community), it would be great if we could discuss this or, perhaps, an alternative approach 🤝