-
Notifications
You must be signed in to change notification settings - Fork 18
Document behavior of ESM packages that lack main
field
#73
Comments
In CJS, omitting a main and an index.js makes your package not requirable. I’d expect the same for ESM. |
My question is about omitting main but providing an index.js. I'd expect this to fail to resolve when the package type is |
I would assume that ESM defaults to main being |
I'd love to define |
I would expect it to work, with an index.mjs as well. |
With extension resolution magic turned on - yes. Without - I wouldn't expect |
In ESM even without extension resolution, I’d expect a literal index.mjs to work. |
See https://nodejs.org/dist/latest/docs/api/modules.html#modules_all_together, specifically LOAD_AS_DIRECTORY. IMO https://nodejs.org/dist/latest/docs/api/esm.html#esm_package_entry_points should be explicit about what happens when
Also noticed while looking at this https://nodejs.org/dist/latest/docs/api/modules.html#modules_all_together Another related edge case is what happens when an in-package directory contains an |
Example package.json:
Assuming
index.js
exists, what is the expected behavior ofimport something from 'foo-bar'
? Is this expected to throw a resolve error due to"type": "module"
as would happen trying to import from a directory? If"type": "module"
where not specified (foo-bar is CJS) would the import statement follow the CJS resolution rules and findindex.js
?I thought of this looking at #72, thinking about expected behavior when specifying
"exports": {}
withoutmain
. It seems like this could be uses to provide CLI only packages that intentionally do not provide an API.The text was updated successfully, but these errors were encountered: