Bug: settings in `tsconfig.json#paths` and `package.json#imports` conflicts
#60,821 opened on Dec 19, 2024
Repository metrics
- Stars
- (48,455 stars)
- PR merge metrics
- (Avg merge 6d 17h) (9 merged PRs in 30d)
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:
"rootDir": "."in thetsconfig.jsonfile, which is required only for VS Code andeslint.config.mjs;pathsin thetsconfig.jsonfile creates an alias for the path#lib/*, pointing to./src/*;importsin thepackage.jsonfile creates an alias for the path#lib/*, pointing to./dist/*.
In such cases, TypeScript suggestions merge content from both the ./dist/* and ./src/* directories:
🙁 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
- The setting described in point 2 should take higher precedence for TypeScript over the setting in point 3.
- 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.