microsoft / microsoft/TypeScript

Dynamically importing JSON should require import attribute with node16/nodenext

Offen
#60,598 1 Kommentar 0 Reaktionen 1 zugewiesene Person Auf GitHub ansehen

@andrewbranch arbeitet bereits daran.

Seit 28.11.2024.

Needs Investigation
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

🔎 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())).

Beitragsleitfaden

Beitragsleitfaden öffnen

Erste Schritte

  1. Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
  2. Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
  3. Forke das Repository und arbeite in einem Branch.
  4. Öffne einen Pull Request, der die Issue-Nummer nennt.

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.