π Search Terms
"module", "default", "esnext", "v6"
π Version & Regression Information
This changed between versions V5 and V6
β― Playground Link
This isn't an issue in Playground, because you're required to enter a value for the module.
https://www.typescriptlang.org/play/?#code/FASwtgDg9gTgLgAgGZSsmUwIEQDoD0KUuAVgM5QB22CA7iHABYIDeCcAnhAKYBcO5KjQC+AbmDAAxlQoAbbrllQA5gAoiASlFA
π» Code
-
package.json
{
"name": "testcase",
"version": "1.0.0",
"type": "module",
"dependencies": {
"typescript": "6.0.2"
}
}
-
index.ts
import foo from "./foo.json" with { type: "json" };
console.log(foo);
npm install
npc tsc index.ts
π Actual behavior
index.ts:1:30 - error TS2823: Import attributes are only supported when the '--module' option is set to 'esnext', 'node18', 'node20', 'nodenext', or 'preserve'.
1 import foo from "./foo.json" with { type: "json" };
~~~~~~~~~~~~~~~~~~~~~
π Expected behavior
No error because module defaults to esnext.
Additional information about the issue
In Announcing TypeScript 6.0, it says module defaults to esnext: Similarly, the new default module is esnext, acknowledging that ESM is now the dominant module format.
But in TSConfig Reference, it's CommonJS if target is ES5; ES6/ES2015 otherwise.
In the code, I don't think the default value is esnext. Otherwise, we wouldn't be getting the TS2823 error.
π Search Terms
"module", "default", "esnext", "v6"
π Version & Regression Information
This changed between versions V5 and V6
β― Playground Link
This isn't an issue in Playground, because you're required to enter a value for the
module.https://www.typescriptlang.org/play/?#code/FASwtgDg9gTgLgAgGZSsmUwIEQDoD0KUuAVgM5QB22CA7iHABYIDeCcAnhAKYBcO5KjQC+AbmDAAxlQoAbbrllQA5gAoiASlFAπ» Code
package.json{ "name": "testcase", "version": "1.0.0", "type": "module", "dependencies": { "typescript": "6.0.2" } }index.tsnpm installnpc tsc index.tsπ Actual behavior
π Expected behavior
No error because
moduledefaults toesnext.Additional information about the issue
In Announcing TypeScript 6.0, it says
moduledefaults toesnext: Similarly, the new defaultmoduleisesnext, acknowledging that ESM is now the dominant module format.But in TSConfig Reference, it's
CommonJSiftargetisES5;ES6/ES2015otherwise.In the code, I don't think the default value is
esnext. Otherwise, we wouldn't be getting the TS2823 error.