Dynamically importing JSON should require import attribute with node16/nodenext

オープン
#60,598 コメント 1 件 リアクション 0 件 担当者 1 名 GitHub で見る

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

2024年11月28日 から。

評価

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

説明

Needs Investigation
🔎 Search Terms

dynamic import, import attribute, resolveJsonModule,

🕗 Version & Regression Information
⏯ Playground Link

https://github.com/kirkwaiblinger/repro-TS-dynamic-json-import-validation

💻 Code
// module: node16/nodenext, resolveJsonModule
// .cts or .mts, it doesn't matter.

async function main() {
    const somethingDynamic = await import('./someThing.json');
    console.log('dynamically imported JSON:', somethingDynamic);
}

main();

export {}
🙁 Actual behavior

No error, even though this is a runtime error in nodejs.

🙂 Expected behavior

Error because dynamic import('./someThing.json') requires import attribute.

Additional information about the issue

Unlike the static import case, this is the case for both commonjs and esm outputs, since import() is available in commonjs modules in node and has the same semantics there as the ESM import (and therefore TS doesn't transform the import() statement to a Promise.resolve(require())).

主要言語
Go
スター
111k
フォーク
14.4k
平均マージ
1日 19時間
マージ済み PR(30日)
117

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

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

はじめの一歩

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

microsoft/TypeScript のほかの issue

microsoft/TypeScript の issue をすべて見る

似ている issue

Go の issue をもっと見る

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

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