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

Field main in package.json incorrectly refers to ESM, not CJS version #352

Closed
tkalliom opened this issue Dec 16, 2020 · 2 comments
Closed
Labels

Comments

@tkalliom
Copy link

From the npm documentation:

The main field is a module ID that is the primary entry point to your program. That is, if your package is named foo, and a user installs it, and then does require("foo"), then your main module's exports object will be returned.

Since require operates on CJS modules, it makes no sense to declare an ESM main. Instead of "main": "esm/index.js", hashids should have "main": "cjs/index.js".

A consequence of this that we hit is that on older (but still LTS) versions of Node.js which do not have the exports mechanism, doing require("hashids") attempts to load hashids/esm/index.js, which fails due to that file being ESM, unsupported by Node.js. (We use TypeScript. The failure just mentioned occurs when we try to run our transpiled tests. We can’t directly load the module hashids/cjs either, since for our production build we use Rollup, the plugin-node-resolve of which was recently updated to respect exports, so it does not rollup subpaths not listed in exports)

@niieani
Copy link
Owner

niieani commented Dec 18, 2020

Thanks for the detailed report @tkalliom!

@niieani
Copy link
Owner

niieani commented Dec 18, 2020

🎉 This issue has been resolved in version 2.2.4 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

No branches or pull requests

2 participants