You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Figure out how to deal with annoying node: prefix in auto-imports from @types/node #43842
Nowadays @types/node ships with built-ins like fs as well as node:fs. Accidentally auto-importing these are extremely annoying if you're trying to target older versions of Node.js.
We should consider
inferring the best type of auto-import from your project
pick the older style of imports one until Node 16 14 becomes the last supported version
Thanks for opening an issue—this has been on my mental to-do list since Ben Lichtman (@uniqueiniquity) brought it up. I’m actually surprised we haven’t gotten a flood of complaints about it already 🤔
Unfortunately, some applications (like ours) are depending on these module specifiers to work in TypeScript and also VS Code: DefinitelyTyped/DefinitelyTyped#52595
Could the fix in #42764 be prioritized so that node: prefixes stay valid module specifiers?
I guess what I would hope for (although I'm not sure if this is the changes described in #42764) would be to satisfy both requirements (prefixed and unprefixed builtin module specifiers):
the node: definitions stay in to not break users who are using them
the non-prefixed versions also stay there
the non-prefixed versions are selected for auto-imports (no user configuration for selecting the node: versions for now)
Even if #42764 was fixed we would not be able to use this feature as the typings need to support old versions.
Simon Schick (@SimonSchick) you’re referring to the node: protocol imports not being supported in CJS require prior to Node 16, right? But if/when that gets backported to Node 14, or when you start writing new types for Node 16, you’d be able to use the feature at that point, right?
Activity
andrewbranch commentedon Apr 27, 2021
Thanks for opening an issue—this has been on my mental to-do list since Ben Lichtman (@uniqueiniquity) brought it up. I’m actually surprised we haven’t gotten a flood of complaints about it already 🤔
jakebailey commentedon Apr 27, 2021
I think it's very likely that people just have old versions of the packages installed, predating DefinitelyTyped/DefinitelyTyped#51107.
I know I hit this and it's frustrating, but I'm pretty diligent about updating my stuff regularly.
jakebailey commentedon Apr 27, 2021
And, this may go away in short order with DefinitelyTyped/DefinitelyTyped#52595.
DanielRosenwasser commentedon Apr 28, 2021
CC Ron Buckton (@rbuckton) we don't really understand this well enough, and I heard there's some churn going into DefinitelyTyped?
andrewbranch commentedon Apr 28, 2021
#42764 for reference
sheetalkamat commentedon Apr 28, 2021
Also needs handling for ATA: https://github.com/microsoft/TypeScript/blob/master/src/jsTyping/jsTyping.ts#L32 ?
karlhorky commentedon May 7, 2021
It seems like the PR from Simon Schick (@SimonSchick) was merged DefinitelyTyped/DefinitelyTyped#52595
Unfortunately, some applications (like ours) are depending on these module specifiers to work in TypeScript and also VS Code: DefinitelyTyped/DefinitelyTyped#52595
Could the fix in #42764 be prioritized so that
node:prefixes stay valid module specifiers?SimonSchick commentedon May 7, 2021
Even if #42764 was fixed we would not be able to use this feature as the typings need to support old versions.
karlhorky commentedon May 8, 2021
I guess what I would hope for (although I'm not sure if this is the changes described in #42764) would be to satisfy both requirements (prefixed and unprefixed builtin module specifiers):
node:definitions stay in to not break users who are using themnode:versions for now)Also mentioned that over here: DefinitelyTyped/DefinitelyTyped#52595 (comment)
andrewbranch commentedon May 10, 2021
Simon Schick (@SimonSchick) you’re referring to the
node:protocol imports not being supported in CJSrequireprior to Node 16, right? But if/when that gets backported to Node 14, or when you start writing new types for Node 16, you’d be able to use the feature at that point, right?SimonSchick commentedon May 10, 2021
No, I'm talking about the fact that node typings lag several TS versions behind for compatibility.
karlhorky commentedon May 30, 2021
So looks like the
node:scheme / prefix was backported to Node.js 14.13.1 / 12.20.0 🎉https://nodejs.org/api/esm.html -> link "node: Imports" (links with anchors don't scroll properly right now)
karlhorky commentedon May 30, 2021
Ah, maybe
require/ CommonJS support is not quite there yet for v14 and v12:DefinitelyTyped/DefinitelyTyped#52595 (comment)
karlhorky commentedon Jul 3, 2021
@types/node@16.0.0has been published now - thenode:schema / prefix now works again properly:Pytal commentedon Aug 14, 2021
As the
node:import URL scheme has been backported tov14.13.1andv12.20.0https://nodejs.org/api/esm.html#esm_node_importsWill
@types/nodefor versions 14 and 12 be updated?SimonSchick commentedon Aug 14, 2021
I probably won't do it as I prefer working on the bleeding edge stuff, but the process is relatively trivial.
declare modulefor each module declaration that re-exports everything with thenode:prefixnode:prefix.You can use the current typings as an example or even just copy/paste from there.
ExE-Boss commentedon Aug 14, 2021
Pytal
That’s only in ECMAScript Module
importstatements, not the CommonJSrequire(…)function.