microsoft/typescript-go

tsc vs tsgo: error for json import with module/moduleResolution nodenext in type="module" package

Closed this issue · 3 comments

Steps to reproduce

mkdir tsgo-vs-tsc
cd tsgo-vs-tsc
npm init -y
npm pkg set type=module
npm i typescript @typescript/native-preview -D
npx tsc --init --module nodenext --moduleResolution nodenext
echo "import packageJson from './package.json' with {type: 'json'}; console.log(packageJson);" > main.ts
npx tsc --noEmit
npx tsgo --noEmit

Behavior with typescript@5.8

No type errors.

Behavior with tsgo

main.ts:1:25 - error TS2732: Cannot find module './package.json'. Consider using '--resolveJsonModule' to import module with '.json' extension.

1 import packageJson from './package.json' with {type: 'json'}; console.log(packageJson);
                          ~~~~~~~~~~~~~~~~


Found 1 error in main.ts:1

Are you sure that’s with 5.8? The default for resolveJsonModule changed in 5.9, with the --module node20 PR. We just haven’t ported 5.9 PRs yet.

apologies, it's 5.9. you are correct. should I close this? or do you want it open for tracking purposes?

We’re already tracking it by the PR where it changed in 5.9, so we can close this.