Open
Description
New --module
Targets for Node.js
- Previously, we were pretty loose about JSON
import
s innodenext
.- We need to stop allowing named imports from these JSON files.
- Also, Node.js requires you to use import attributes for JSON files.
- In 5.7 we added fixes for cases when we resolve to JSON files.
- We enabled this for
node16
as well, but we error saying that you can only use import attributes innodenext
. - In Node.js 16, you can only use import assertions (the old deprecated thing), not import attributes.
- We will probably make things loose again in
node16
as well - no checks for JSON modules.
- We will probably make things loose again in
- Node.js 16 is already EOL.
- So where does this leave us?
- Node.js 18 is still in maintenance, but does support import attributes.
- Node 23 will have
require(ESM)
support.
- Proposal:
--module nodenext
allowsrequire(ESM)
(for Node.js 23/24, possibly 22)- Eventually settle on a specific line.
--module node20
depending on if the above features get back-ported.--module node18
for import assertions and JSON import checks (whatnodenext
should be in TypeScript 5.7)--module node16
to be deprecated farther down.- It is not the most ideal state (it is EOL, doesn't support JSON imports correctly), but TBD.
- We like this plan, we feel okay to move forward with this for TypeScript 5.8.