-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
doc: ES module wrapper guide #34714
Comments
What do you mean by that? The current example does support both contexts. I does even support old version of Node.js. Why do you think your example would be clearer? If anything, using explicit extension ( |
I agree with you that |
@fox1t that's a valid point! Maybe we could change only the {
- "type": "module",
+ "type": "commonjs",
"main": "./index.cjs",
"exports": {
"import": "./wrapper.mjs",
"require": "./index.cjs"
}
} |
FWIW the specific layout here was intentional. If you are using exports node will node utilize package.main. Older versions of node.js that don't support Exports also don't support ESM, so main can be used as a fallback for legacy versions of node. Perhaps it would be better if we names it In regards to the is-promise article, some of the documentation that currently exists was written specifically in response. |
@MylesBorins I am not sure I fully understand what you said here. I think we can think only about the newer Node.js versions, that support What I've understood about native ESM in Node.js, is that That's why I think that writing {
"type": "commonjs",
"main": "./index.js",
"exports": {
"import": "./wrapper.mjs",
"require": "./index.js"
}
} in the doc section where we talk about porting legacy packages to be consumed by both world, is way better. I think that 99% of the packages and package maintainers are using @aduh95 I agree with you that Of course, I might be wrong about this topic too and in that case, I am open to understanding how it works and, if needed, to update the docs accordingly! As final words, @MylesBorins that addition about |
@fox1t There is no version of Node.js that will utilize main if exports exists that also supports modules, thus having a .js file there is essentially setting the module up to fail in all those environments as the .js file will be ESM. |
@MylesBorins I know and completely agree with you about the fact that there will never be overlaps on main and exports props. {
...
"type": "module", // <---- this is the problem I am pointing out here
"main": "./index.js", // this line is already present in my package.json
"exports": {
"import": "./wrapper.mjs",
"require": "./index.cjs"
},
...
} to my package.json and since my current files have I hope that this clarifies why having P.S. I see this mistake done many times into the wild, by several developers with different skill levels. |
We could remove the |
@fox1t apologies for missing the point you were trying to get across. +1 on removing module from the example. |
@MylesBorins no worries! I am happy I've managed to explain what I meant! Said that, where are we going to remove |
@fox1t I think opening a PR with just removing module should be sufficient {
"main": "./index.js",
"exports": {
"import": "./wrapper.mjs",
"require": "./index.js"
}
} |
Ok, I am going to make the PR. |
Closed by ac3049d |
📗 API Reference Docs Problem
Location
Affected URL(s):
Description
I was wondering if it would be better to write this example as:
since its current form might be misleading for package maintainers that want to support both ESM and CommonJS contexts. Maybe what happened here could be prevented if the documentation was more clear.
submit a pull request.
The text was updated successfully, but these errors were encountered: