Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

(Experimental) Add ESM support #300

Draft
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

marvin-j97
Copy link

This PR adds ESM support by adding an index.mjs file and the appropiate package.json field (module), I also added exports. The import uses the experimental JSON module syntax (https://nodejs.org/api/esm.html#json-modules), which requires Node 16.14+.

I also added a Github workflow and a new test file that uses Node's test runner. FWIW, the tests merged at some point in the future.


An alternative would be to use createRequire, but it does not seem well supported by bundlers:
evanw/esbuild#1828
rollup/rollup#4274


Another alternative would be to just drop CommonJS altogether, and only provide a ESM export, dropping Node 0 - 16.13 support, and bumping one major version to mime-db@2.0.0. After all, everything up to Node 14 has reached EOL, even Node 16 is getting close. That way, the engines field in the package.json could also be adjusted appropiately.

Maybe some years down the line...


PS: It's 2023, I think it's OK to drop some old Node versions and io.js from the CI :)
It could be massively simplified by just using a node-version matrix entry and the setup-node GH action.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant