microsoft / microsoft/TypeScript

`--showConfig` doesn't resolve `paths`

Offen
#55,825 0 Kommentare 2 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen

Dieses Issue hat noch niemand übernommen.

Bug Domain: Module Resolution Help Wanted
Vorherrschende Sprache
Go
Sterne
111k
Forks
14.4k
Ø Merge
1 T. 19 Std.
Gemergte PRs (30 T.)
117

Beschreibung

🔎 Search Terms

"showConfig", "paths", "extends", "relative"

🕗 Version & Regression Information

v5.2.2 (no regression AFAIK)

⏯ Playground Link

https://stackblitz.com/edit/stackblitz-starters-gst2kr?file=tsconfig.json

Commands:

  • npm run config -> tsc --showConfig

  • npm run trace -> tsc --noEmit --traceResolution
    Use this to confirm that foo does resolve to ./this-path-should-be-in-config/bar.ts

💻 Code

No response

🙁 Actual behavior

Given a tsconfig that extends another config:

./tsconfig.json

{
  "extends": "./this-path-should-be-in-config/tsconfig.json"
}

./this-path-should-be-in-config/tsconfig.json

{
  "compilerOptions": {
    "paths": {
      "foo": ["./bar"]
    }
  }
}

The resolved tsconfig (via tsc --showConfig) doesn't reflect that ./bar is actually resolved relative to ./this-path-should-be-in-config/tsconfig.json:

{
    "compilerOptions": {
        "paths": {
            "foo": [
                "./bar"
            ]
        }
    },
    "files": [
        "./file.ts"
    ]
}
🙂 Expected behavior

For the config to include the relevant information (e.g. the relative path):

{
    "compilerOptions": {
        "paths": {
            "foo": [
                "./this-path-should-be-in-config/bar"
            ]
        }
    },
    "files": [
        "./file.ts"
    ]
}

Currently, it seems to indicate that paths is resolved relative to the CWD. When it's in fact relative to this-path-should-be-in-config.

It's also impossible for a custom TypeScript paths resolver (e.g. https://github.com/privatenumber/get-tsconfig) to correctly resolve the paths aliases based on this output.

Additional information about the issue

From https://github.com/privatenumber/get-tsconfig/pull/62

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 StackBlitz-Reproduktion und führe npm run config (tsc --showConfig) sowie npm run trace (tsc --noEmit --traceResolution) aus. Vergleiche die geerbten paths-Werte in den beiden tsconfig.json-Dateien mit dem durch das Tracing angezeigten aufgelösten Modulpfad. Fertig ist die Aufgabe, wenn --showConfig den Pfad relativ zur erweiterten Konfigurationsdatei meldet und dabei die demonstrierte Aliasauflösung erhalten bleibt.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
compilers
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
45/100

Neue Issues direkt in Ihr Postfach

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