microsoft / microsoft/TypeScript

Bug: settings in `tsconfig.json#paths` and `package.json#imports` conflicts

Aperta
#60,821 3 commenti 1 reazione 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Bug Domain: Module Resolution Help Wanted
Lingua principale
Go
Stelle
111k
Fork
14.4k
Merge medio
1g 19h
PR unite (30g)
117

Descrizione

🔎 Search Terms

"package.json imports path"

🕗 Version & Regression Information
  • This is the behavior in every version I tried, and I reviewed the FAQ for entries about this issue
⏯ Playground Link

No response

💻 Code

My repository is intended to reproduce a bug that manifests when the following three settings are combined:

  1. "rootDir": "." in the tsconfig.json file, which is required only for VS Code and eslint.config.mjs;
  2. paths in the tsconfig.json file creates an alias for the path #lib/*, pointing to ./src/*;
  3. imports in the package.json file creates an alias for the path #lib/*, pointing to ./dist/*.

In such cases, TypeScript suggestions merge content from both the ./dist/* and ./src/* directories:


Image


🙁 Actual behavior

As you can see, file1.js, file2.js, and index.js appear at the same level as the src and test folders, which is incorrect.

🙂 Expected behavior
  1. The setting described in point 2 should take higher precedence for TypeScript over the setting in point 3.
  2. In any case, the settings in points 2 and 3 should not be merged.
Additional information about the issue

If in point 1 the setting is changed to "rootDir": "src", the bug disappears. However, in this case, you cannot use "include": ["test"] in the tsconfig.json file, which is very inconvenient. Instead, it is more practical to use the "rootDir": "src" setting in the tsconfig.build.json file.

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.

Direzione di ricerca

Inizia riproducendo il comportamento nel repository collegato, confrontando le impostazioni di tsconfig.json per rootDir e paths con gli import di package.json. Indaga sul motivo per cui i suggerimenti combinano elementi di ./src e ./dist; il lavoro è completato quando le impostazioni non vengono più unite e nei suggerimenti viene riflessa la precedenza TypeScript prevista.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
typescript
Ambito
compilers
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.