-
Notifications
You must be signed in to change notification settings - Fork 12.6k
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
Start Node ESM stable version at Node16 #48879
Conversation
|
@@ -33101,10 +33101,11 @@ namespace ts { | |||
Diagnostics.await_expressions_are_only_allowed_at_the_top_level_of_a_file_when_that_file_is_a_module_but_this_file_has_no_imports_or_exports_Consider_adding_an_empty_export_to_make_this_file_a_module); | |||
diagnostics.add(diagnostic); | |||
} | |||
if ((moduleKind !== ModuleKind.ES2022 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind === ModuleKind.NodeNext && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) { | |||
if ((moduleKind !== ModuleKind.ES2022 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind >= ModuleKind.Node16 && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) { |
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.
Actually, this check is wrong and the tests reflect that. Should it be
if ((moduleKind !== ModuleKind.ES2022 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind >= ModuleKind.Node16 && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) { | |
if ((moduleKind !== ModuleKind.ES2022 && moduleKind !== ModuleKind.ESNext && moduleKind !== ModuleKind.System && !(moduleKind < ModuleKind.Node16 && getSourceFileOfNode(node).impliedNodeFormat === ModuleKind.ESNext)) || languageVersion < ScriptTarget.ES2017) { |
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.
Normally we still emit warnings of some kind when using experimental features, which would still be in all stable versions of node, at least until nodejs/node#42875 ships in the next version of node 18.
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.
So maybe until TLA becomes non-experimental we could issue an error like
Top-level 'await' is currently experimental in Node.js. It can only be enabled when the 'module' option is set to 'nodenext'.
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.
On a related note, we should probably remove the experimental warning for json imports in nodenext. Afaik, they've stabilized in node 18. At least the version with the import assertion, anyway. It's contentious among the node maintainers.
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.
The PR is already merged - that seems like a pretty strong sign that it will be stable, right?
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.
The test wasn't wrong, it was just very confusing because the code was in a CJS file. I've updated the check there.
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.
Yeah, it'll be stable in the next release of node 18, it just hasn't shipped yet, and I don't know if it'll be backported to 16 or not.
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.
At what point do they stop backporting features like that? Maintenance LTS? Is it practical to not create a named moduleResolution target until it solidifies?
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.
Changes are backported to LTS versions unless they're somehow breaking from what I understand, while maintenance LTS versions only get security patches. At least I think that's the general policy. (The definition of "breaking" being the somewhat subjective part)
bdf9922
to
52d1ea5
Compare
Newest updates give a better error message when you have TLA in a CJS module. |
…ger experimental.
Most recent changes remove the error message for importing a JSON module under Node16 and NodeNext. |
A decent amount of stuff seems to already use/support Node 12. Should we keep it undocumented and provide an error when using it, but continue supporting it otherwise? |
I mean, as I said back in the issue, I'm all for having newer stable versions to match the node versions people wanna target, alongside the existing versions we support, in the same way we build out a new esXXXX target every year (potentially if only to match up that node version to the correct esXXXX target automatically). If we only do even-numbered (and thus LTS) node versions, we should only need to add one every year or so as well. Sounds like we have fairly good reasons to have both node16 and node18, in addition to 12, since 16 has all those fun es2022 features and 18 has stablized tla and JSON imports, while 12 already has some use. |
Spoke with @ahejlsberg and @andrewbranch on this. We could just say Node18 as the initial minimum target which would simplify a bit for us; however, like you've mentioned, Node 18 can get more and it's not yet the active LTS. So let's start with Node 16 and if we see anything that diverges, we can add a Node18 target down the line. |
Consensus was on not providing a workaround for nightly-only users. Either you have nightly TS in a lockfile or you've signed yourself up to staying up-to-date. |
Just remember that any perceived simplicity from initially supporting fewer explicit node versions is very likely a short-lived pipe dream at best - we will have to add more, the same way we add esXXXX targets every year. The kind of big-bang module system update that happened with the esm transition is not how node usually does development, usually you get more minor changes each release, as we can already see between 12, 14, 16, and 18. (And the only reason we didn't see a need to update the commonjs resolver for so long is because all those minor resolver changes were being banked up for the node 12 esm drop - even the cjs ones.) If the issue is the perceived complexity or messaging of many targets, that can is only being kicked, not fundamentally solved. IMO, a longer term more complete solution would be following in the footsteps of... pretty much every js transforming tool in the js community (eg, babel via preset-env, rollup's target argument), and taking arbitrary engine versions/ranges and mapping them automatically to our internal feature flags (eg, es target, module (resolution), and emit features). That would be more predictable into the future, imo. Messaging is probably simpler: 'specify all desired target runtimes, eg |
See microsoft/TypeScript#48879 for background
@@ -134,296 +134,33 @@ Output:: | |||
|
|||
[[90m12:00:26 AM[0m] Building project '/src/src-types/tsconfig.json'... | |||
|
|||
[[90m12:00:33 AM[0m] Project 'src/src-dogs/tsconfig.json' is out of date because output file 'src/src-dogs/dog.js' does not exist |
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.
Can you fix the tests to modify lib file so there are no errors are we are really testing the scenario.
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.
Created #48974
@@ -16,7 +16,7 @@ export type TheNum = 42; | |||
export type { TheNum } from './const.cjs'; | |||
|
|||
//// [/user/username/projects/myproject/packages/pkg2/tsconfig.json] | |||
{"compilerOptions":{"composite":true,"outDir":"build","module":"node12"}} | |||
{"compilerOptions":{"composite":true,"outDir":"build","module":"node16"}} | |||
|
|||
//// [/user/username/projects/myproject/packages/pkg2/package.json] |
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.
Same for this
Today Node 16 provides two really nice characteristics:
??=
,#private
fields, numeric separators, error causes, and more. This is nice because even if you're not transforming your input code, you won't get an error for using some of these constructs.This PR starts our minimum stable version of Node targeting and resolution to Node 16 instead of Node 12.
There is a caveat which @weswigham pointed out, which is that top-level
await
isn't yet documented as stable.Fixes #48646