microsoft / microsoft/TypeScript

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

Open
#60,821 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Bug Domain: Module Resolution Help Wanted
Dominant language
Go
Stars
111k
Forks
14.3k
Avg merge
2d 4h
Merged PRs (30d)
132

Description

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the behavior in the linked repository, comparing tsconfig.json settings for rootDir and paths with package.json imports. Investigate why suggestions combine entries from ./src and ./dist; done when the settings are no longer merged and the expected TypeScript precedence is reflected in suggestions.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.