-
-
Notifications
You must be signed in to change notification settings - Fork 34.2k
esm: add support for JSON import assertion #40250
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
esm: add support for JSON import assertion #40250
Conversation
11f7f0e to
9ee9fdc
Compare
|
Is there no way we could add a separate flag that allows assertionless JSON import? |
|
@aduh95 Thank you for doing this, I really appreciate it. I don’t have any objections with your intent of this PR, so I’m happy for it to land once we can work through some technical discussions. I appreciate your patience. In the meantime, can we close the other versions of this so that there’s no confusion? #39921 and #40210, are there any others? So that in the end it’s just the PR that adds support for assertions (this PR) and the PR that unflags JSON modules (#37375). Also #40249 feels pretty interdependent on this PR; I think it should be fine, but it might change depending on discussions in this one, so could we maybe close that one and land that change as part of this? Re “don’t land on v14.x,” is that because the version of V8 in 14.x doesn’t support unflagged |
Correct, it doesn't support assert syntax at all (that was added in V8 9.1 IIRC, Node.js v14.x uses V8 8.4). |
|
@aduh95 and I discussed this. Here’s what I think are the to-do items to land this PR:
|
8b18aaf to
f889864
Compare
17f81db to
13b63c2
Compare
13b63c2 to
10ba639
Compare
Import assertion support has landed behind a flag in V8 for quite some time, this PR enables it by default in Node.js. This PR allows folks to write JS code that uses import assertions syntax. Only type: “json” is supported for now, although JSON modules support in Node.js is still experimental and behind
--experimental-json-modulesCLI flag.This PR also disables importing of JSON modules without using an assertion, by popular demand. Support for those can be added using loader hooks.
Refs: #37375 (comment)
Alternative to #39921
/cc @nodejs/modules @nodejs/loaders