-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
docs: clarify dynamic imports and side effects #31479
Conversation
@nodejs/modules-active-members |
Thanks for this PR. A few broad thoughts:
|
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import shows It does seem like large portions of this existing page could be linking to MDN instead, if that's the criteria. But I like seeing it in the Node docs because historically it didn't always match module spec behavior. I understand it's supposed to match the spec now, but it's still useful to explicitly say "for dynamic imports, we match the spec found here", etc. Regarding side effects, they can and do have them. I had a need to do this with a module that I don't maintain, which is why I added it to these docs. (I agree it's not ideal to have side effects, but ideal is different from reality.) The MDN article I linked to even has a "Import a module for its side effects only" section with the same info. So in summary, I'm ok with linking to MDN for whatever is there. If you have any more specific suggestions about what I should keep and what I should link, please let me know. |
I think we should just link to MDN |
I think anything that’s not particular to Node should be left out of the Node docs. Side effects are a general language thing not particular to Node; we can just link to a section of the MDN page for them. The MDN docs themselves are a wiki; you can edit those pages. |
Hey team, seems like with the time that has passed we don't want to land this. Do we want to add a note pointing to MDN? |
I would be fine with an early mention of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left some feedback comments
I can add links to MDN and adjust the text for the "anything that’s not particular to Node should be left out of the Node docs" guideline before this is merged. |
I updated the dynamic imports section on MDN: https://wiki.developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Dynamic_Imports And then removed some of that text from this PR and instead linked to MDN. This can be merged now as far as I am concerned. |
This seems to have the approvals necessary to land, is there anything else holding it back? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This all seems fine, but there's not really anything particular to Node added in this PR. This feels more like content that should be in MDN, explaining basics about import()
that apply to any environment. Indeed, it's already there, in https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Import_a_module_for_its_side_effects_only and https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/import#Importing_defaults. Rather than repeating that text, could we just mention and link to it?
@GeoffreyBooth What exactly do you want changed? I'm already linking to those MDN sections you mention, and the only things left in this PR are examples that I believe are unique to Node. If those examples (particularly about needing to destructure "default") are part of the spec, then I guess those could also be moved to MDN. But I don't know that they are. I left the mention of importing CommonJS in here because the MDN article isn't about ESM-CJS interoperability and that I think is another thing unique to Node. Also I left the |
I guess to phrase one thing I said as a question, is it true that If they're all the same, then I'll move more of that to MDN docs. I do still think there's value in having the examples here that explicitly say "to import from CommonJS or ESM", which is a Node-specific clarification of the MDN docs. This has been the most confusing thing for people I've been trying to help transition to ESM. I don't know who if anyone is "in charge" of MDN docs decisions, but another approach could be to remove some of these sections entirely from the Node docs and update the MDN docs to have Node-specific examples. I don't usually see Node examples called out in MDN docs, but I don't know if there's any rule against it. |
@aldeed yes, they're all the same - |
I don't feel strongly, as this is useful information, but in general the Node docs should try to be specific to Node as much as possible and not include generic JavaScript guidance. The more superfluous information that our docs contain, the longer the docs get and the less people read of them 😄 and the more there is for us to ensure correctness of and to maintain. To be honest, I don't see anything added in this PR that's specific to Node. The previous text already included the one Node-specific thing, that Is there anything in particular that you can point to that this PR adds that is specific to Node? Or that is an especially common hazard for users to fall into in a Node context, separate from other environments' ESM contexts? |
OK I've moved more of this over to MDN What's left here is the addition of two links to those updated MDN sections, some minor clarifications of the language, and one anchor link fix. I rebased and squashed everything into one commit. These remaining changes seem worth merging to me, but feel free to close this if there isn't agreement. Thanks all for helping me work through this. |
Co-Authored-By: Geoffrey Booth <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for working through this with us!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
PR-URL: #31479 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Myles Borins <[email protected]>
Landed in f92df33 |
Signed-off-by: Richard Lau <[email protected]> PR-URL: #32462 Refs: #31479 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Beth Griggs <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
PR-URL: #31479 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Myles Borins <[email protected]>
Signed-off-by: Richard Lau <[email protected]> PR-URL: #32462 Refs: #31479 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Beth Griggs <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
PR-URL: nodejs#31479 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Myles Borins <[email protected]>
Signed-off-by: Richard Lau <[email protected]> PR-URL: nodejs#32462 Refs: nodejs#31479 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Beth Griggs <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
Backport-PR-URL: #32610 PR-URL: #31479 Reviewed-By: James M Snell <[email protected]> Reviewed-By: Geoffrey Booth <[email protected]> Reviewed-By: Myles Borins <[email protected]>
Signed-off-by: Richard Lau <[email protected]> Backport-PR-URL: #32610 PR-URL: #32462 Refs: #31479 Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: Beth Griggs <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]>
The docs did not explain very well how and why to use dynamic
import()
. Now it does. This should be updated in 12 LTS and maybe other versions, too. Not sure how docs versioning works.Checklist