microsoft / microsoft/TypeScript

[V6] `module` defaults is not `esnext`

オープン
#63,330 コメント 7 件 リアクション 5 件 担当者 1 名 GitHub で見る

@DanielRosenwasser がすでに取り組んでいます。

2026年4月1日 から。

Docs
主要言語
Go
スター
111k
フォーク
14.3k
平均マージ
2日 4時間
マージ済み PR(30日)
132

説明

### 🔎 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`

```json
{
"name": "testcase",
"version": "1.0.0",
"type": "module",
"dependencies": {
"typescript": "6.0.2"
}
}
```

- `index.ts`

```ts
import foo from "./foo.json" with { type: "json" };

console.log(foo);
```

1. `npm install`
2. `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_](https://devblogs.microsoft.com/typescript/announcing-typescript-6-0/#simple-default-changes), 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_](https://www.typescriptlang.org/tsconfig/#module), 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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。