-
Notifications
You must be signed in to change notification settings - Fork 44
The type field and .node
#474
Comments
If memory serves it was pulled out due to compat concerns. Don't remember when, but seems we should discuss what type "module" is intended for rather than adding .node to it prematurely |
I’ll again link to #283 as the imo preferred way to handle this ambiguity that will come up for an unknowable number of new module types in the future. |
I think my memory was that we intended for
If node doesn't support a new extension, then it doesn't seem to be valuable for a package to declare it. If a loader hook adds the support for loading a format, it can also provide the format. Allowing packages to come up with their novelty extensions for existing formats doesn't seem like a super compelling use case to me..? Our current direction for loader hooks (determined before loading user code, immutable once set) seem to preclude that the package's extension map can introduce new formats. |
We have two categories of files: those that have an explicit parse goal inherent in the file type, and ambiguous files that can be either Script or Module. My understanding, please correct me:
Yes, this is my recollection as well. We document in https://nodejs.org/api/esm.html#esm_commonjs_json_and_native_modules that JSON and native modules need to be pulled into an ES module via |
@jkrems it's not about allowing novelty extensions (altho ofc it would allow that), it's about not having to decide the semantics of a field like "type" for all future extensions as well as the complex combo of current ones. The extension map would be a subset of loader hooks; they don't conflict as far as I'm aware. |
I'd like to be wary of attempting to see if something "is a Module" (unclear if meaning an Abstract Module Record here or in "type":"module"). WASM can be loaded through import but also just via an API. Virtually anything can be transformed into an Abstract Module Record and many things can be exposed without using Module Records at all (JSON/WASM/etc.). I don't fully understand the comment. |
To me that comes down to the question: Do we believe that we'll add more ambiguous file extensions? As long as extension-less and |
Somewhat echoing @bmeck: No, it can be neither. "module" refers to ESM specifically, not any kind of entry in either "module map"/cache. JSON is always |
@jkrems at least in my last call with Dan they wanted WASI and WASM to be in the same file extension. |
The We only need to worry about how
I’m referring to parse goal. I thought that all WASM files were in parse goal Module, are they not? If so, |
They are not. They are a completely different parser. |
That feels a bit awkward for node. I guess it means that node wouldn't support "raw" WASM imports, only ones with WASI semantics (including capabilities..?). For the former there's always the direct APIs though and fortunately we still have a dedicated experimental flag for importing |
How will browsers support loading WASM? Via I assume WASM has only one parse goal? |
Yes, using script tags (type=module) and/or import. The type wouldn't determine the format/parser used, it determines the loader (classic vs module , though other kinds exist).
Yes, but it is starting to have 2 distinct semantic goals (WASI vs WASM). |
So it sounds like browsers are treated WASM the same way they treat ES module JavaScript. Is there an issue with Node treating |
No, they remain decoupled in terms of format. They use the same loader workflow though.
Yes, that would not allow WASM to be loaded. I don't think I understand this question fully.
This is not true today, per the
This likely won't be possible if WASI/WASM fully diverge. |
That's already true behind
I think one conceptual issue here is that the With this, the |
This is not purely the case, it does have potential alterations to other things like which loader to use for the main entry point even if the file of the main entry point is not "ambiguous". |
@bmeck In all cases I’m just talking about the public API that end users see, with regard to importing/loading the file. It sounds like |
I don't understand this. Not for/against any part of the comment; I simply am confused. |
End users don’t really need to know or care about the module system or what’s happening under the hood. They can just treat |
discussion seems to be focused around WASM after some minor back and forth; maybe we can migrate the last bit of discussion to #457 ; feel free to reopen if there is disagreement |
So far we've told people that
type
can be used to switch how.js
is interpreted. In nodejs/node#31388 @bmeck pointed out that setting it tomodule
also has side-effects on how.node
is interpreted. To me that sounds really counter-intuitive and surprising. Are there any meeting notes for this? Right now I would consider it a bug that's worth fixing.For reference, this is the current effective extension map delta:
I'm omitting
.json
because with experimental JSON modules the difference goes away. But without the flag, it is also affected bytype
.The text was updated successfully, but these errors were encountered: