Uh oh!
There was an error while loading. Please reload this page.
doc: clarify require/import complement exclusivity - #33832
Conversation
guybedford
commented
Jun 10, 2020
//cc @sokra |
bmeck
commented
Jun 10, 2020
I'd just note that "mutual exclusivity" doesn't mean one or the other must be true, just that they both cannot be true, so it seems the example in the original comment about not being able to hit |
guybedford
commented
Jun 10, 2020
Thanks @bmeck for the logical assistance here... ok I've changed the wording to be explicit they that are fully complementary in matching. Let me know if that sounds better. |
bmeck
commented
Jun 10, 2020
sounds good |
sokra
left a comment
There was a problem hiding this comment.
I don't agree with that. That might be true for node in the current state, but I don't think that should be a general precondition.
Other conditions should be allowed for future extensions or alternative module formats.
Esm might be superseded by a new module format in a long distant future. For this you might want to use a new condition zap to point to the zap modules.
Non JavaScript module systems also want to use a different condition. For a css module using @import "package" you may want to use the @import condition name.
sokra
commented
Jun 11, 2020
Mutually exclusive seems fine to me. Meaning when |
hybrist
commented
Jun 11, 2020
To clarify here: the condition is called “import” because it refers to a module graph, not to a module file format. So it may point to a web assembly module or a JSON module, assuming those can be linked into an import-style graph of modules. Just like “require” doesn’t mean CommonJS file format. It could also point to .node or .json files which are also supported in require-style module graphs (potentially). |
guybedford
commented
Jun 11, 2020
@sokra would it help if we specifically adjust the wording to distinguish between |
PR-URL: #33832 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
guybedford
commented
Jun 28, 2020
Landed in f89530f. |
PR-URL: #33832 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
PR-URL: #33832 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
PR-URL: #33832 Reviewed-By: Jan Krems <jan.krems@gmail.com> Reviewed-By: Geoffrey Booth <webmaster@geoffreybooth.com>
This PR adds a small doc change to clearly define that
"import"and"require"are always mutually exclusive in exports (if something was not required then it definitely was imported) when loading an ES module.Currently there isn't clear guidance that when defining in "exports":
that it should never be possible to resolve to
./main.js.For example, other tools and bundlers could interpret
new Worker('pkg')to not be animportorrequirepath at all. Or similarly for other mechanisms of loading in future. When we should always define that loading an ES module goes through theimportpath.Otherwise, this leaves a semantic gap where users might find
defaultmatched by some tools in the above example. By narrowing this gap we ensure we can continue to provide predictability between tools.//cc @nodejs/modules-active-members
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passes