microsoft/TypeScript

Typescript 4.5 resolveJsonModule should also work with node12 and nodenext module and resolveTypes

frank-dspeed opened this issue ยท 2 comments

Bug Report

๐Ÿ”Ž Search Terms

resolveJsonModule typescript 4.5 node node12 nodenext

๐Ÿ•— Version & Regression Information

4.5 +

โฏ Playground Link

Playground link with relevant code

๐Ÿ’ป Code

set resolveJsonModule true and moduleResolution node12 or nodenext in the tsconfig.json

๐Ÿ™ Actual behavior

Errors

TS5070: Option '--resolveJsonModule' cannot be specified without 'node' module resolution strategy.

๐Ÿ™‚ Expected behavior

should work with node12 and nodenext also

JSON imports in esm mode imports at least are still experimental and need a flag, and there's a big kerfuffle over on the node repo as to weather they should require an assert { type: "json" } on the import (see conversations on nodejs/node#37375 and nodejs/node#40250 ). We can allow it for cjs mode imports pretty painlessly, but for esm imports it's still experimental, unfortunately (and not having any named imports is unfortunately going to be a big change from current behavior, too). So the fix for this might not take the shape you're expecting.

@weswigham we use it only for typechecking inside our project https://github.com/rollup/rollup/blob/master/rollup.config.ts

we extract the version fild of the package.json.

also there are .cjs files possible in case of node12 and nodenext where it should be painless to allow it so allow it in general is fine. As there are also none node environments that are working with .mjs and cjs it is fine to enable it