microsoft / microsoft/TypeScript

Dynamically importing JSON should require import attribute with node16/nodenext

Aperta
#60,598 1 commento 0 reazioni 1 assegnatario Vedi su GitHub

@andrewbranch ci sta già lavorando.

Dal 28/11/2024.

Needs Investigation
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

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

Guida per i contributori

Apri la guida per i contributori

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.