microsoft / microsoft/TypeScript

Mechanism to specify input source location to find `package.json` instead of output source location when determining module format

Offen
#63,251 3 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Needs Proposal Suggestion
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.3k
Ø Merge
2 T. 4 Std.
Gemergte PRs (30 T.)
132

Beschreibung

🔎 Search Terms

nodenext, ts2351, construct

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about "A default import of a commonjs module with a default in a esm file doesn't seem to be the default export of that module when module is node16 or nodenext".
⏯ Playground Link

N/A

💻 Code
git clone https://github.com/monsanto/typescript-nodenext-bug
cd typescript-nodenext-bug
npm install
npm run tsc
🙁 Actual behavior
foo/index.ts:6:5 - error TS2351: This expression is not constructable.
  Type 'typeof import("<dir>/typescript-nodenext-bug/.cache/foolib/class")' has no construct signatures.

6 new CBad();
      ~~~~


Found 1 error.
🙂 Expected behavior

It succeeds.

Additional information about the issue
  • This issue requires a composite project, NodeNext, a package boundary, a default export, and a parent directory with a file package.{json, json5, yaml} without type: module.
    • Please note that import default inside foo's package boundary works.
    • One can delete the provided package.json after installing and run node_modules/typescript/bin/tsc --build tsconfig-base.json to test without package.json present.
    • One can see other package extensions trigger the bug by mv package.json package.yaml and pnpm run tsc.
  • This is not a CommonJS project. It doesn't matter that there is a parent package.json without it. Node doesn't even read package.yaml.
    • This is from a real-world monorepo where there is a root pnpm package.json5 for cross-package scripts.

Cross-ref for #62200

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.

Rechercherichtung

Beginne mit der verknüpften typescript-nodenext-bug-Reproduktion: Führe npm install und npm run tsc aus und untersuche anschließend tsconfig-base.json sowie die in der Issue beschriebenen Varianten von package.json, package.json5 und package.yaml. Vergleiche das NodeNext-Modulformat-Ergebnis, wenn die Metadaten des übergeordneten Pakets vorhanden bzw. nicht vorhanden sind; abgeschlossen ist die Aufgabe, wenn die Reproduktion ohne TS2351 erfolgreich ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
node.js, typescript
Bereich
build-system, compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

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