Replies: 2 comments 1 reply
-
Option 3: {
"type": "module",
"exports": {
".": "./index.js"
}
} That would be the one I'd use, it's equivalent to option 2 for the error message and also simpler.
I'm not sure what you mean by that, in Node.js "every" JS files are "importable", as it is possible to import both ESM and CJS. The fact that you list it in the |
Beta Was this translation helpful? Give feedback.
-
i haven't been such a huge fan of package.json lately and tough it have mostly bloated with unnecessary things... i think it better to just rader be more explicit. ryan dhal regretted the hole package.json, extension-less and index thing, and so do i. it's unnecessary and bloated and not how cdn works |
Beta Was this translation helpful? Give feedback.
-
ESM-only packages could export as
Option 1:
Option 2 (can be sugar-ed, but typed verbose for comparison):
Question: Should option 1 or option 2 be preferred?
Background
With option 1, Node.js logs
While option 2 logs:
Option 2 is a lot clear of what to fix, and I'm tempted to do option 2 everywhere too. But currently I'm doing option 1 because other environments can easily know if a package is only
import
-able (can'trequire
) by resolving the exports object without hitting the fs and evaluating it.I notice the docs is slightly leaning towards option 2 too, but not exactly as
import
andrequire
conditions are not environment branches.What to do
If option 1 is preferred, Node.js could improve the error message to check if the
import
condition resolved path exists whenrequire
-ing it (and vice-versa).If option 2 is preferred, I could update https://publint.dev to check this specific case to move the ecosystem towards it.
Beta Was this translation helpful? Give feedback.
All reactions