PhpStorm中tsconfig$paths是什么?如何移除它?
解决PhpStorm中tsconfig$paths重复高亮跳转问题
问题现象
- PhpStorm项目的「External libraries」下出现
tsconfig$paths目录 - 在TypeScript文件中点击「在文件树中查找」时,文件会被高亮两次:一次位于项目文件夹内,另一次在
tsconfig$paths中 - 默认跳转至外部库中的文件,影响正常使用,无法找到移除该目录的方法
用户提供的tsconfig配置
1. tsconfig.app.json
{ "extends": "@vue/tsconfig/tsconfig.dom.json", "include": ["env.d.ts", "src/**/*", "src/**/*.vue"], "exclude": ["src/**/__tests__/*"], "compilerOptions": { "composite": true, "baseUrl": ".", "paths": { "@/*": ["./src/*"], "@root/*": ["../"] } } }
2. tsconfig.node.json
{ "extends": "@tsconfig/node18/tsconfig.json", "include": [ "vite.config.*", "vitest.config.*", "cypress.config.*", "nightwatch.conf.*", "playwright.config.*" ], "compilerOptions": { "composite": true, "module": "ESNext", "types": ["node"] } }
3. tsconfig.json
{ "files": [], "references": [ { "path": "./tsconfig.node.json" }, { "path": "./tsconfig.app.json" } ] }
解决方法
方案1:调整paths别名配置(推荐)
问题根源在于tsconfig.app.json中@root/*": ["../"]的配置,让PhpStorm把上级目录也纳入了tsconfig$paths的解析范围,导致重复索引项目文件。
- 如果不需要
@root这个别名,直接删除该配置项; - 如果确实需要引用上级目录的内容,缩小路径范围到特定文件夹,比如:
"paths": { "@/*": ["./src/*"], "@root/*": ["../shared/*"] }
方案2:排除tsconfig$paths目录索引
- 打开PhpStorm设置(Windows/Linux:Ctrl+Alt+S;Mac:Cmd+,)
- 进入
Languages & Frameworks > TypeScript,在Compiler选项卡点击Edit修改编译选项,添加排除规则:"exclude": ["../**/*"] - 或者进入
Settings > Directories,找到tsconfig$paths对应的目录,右键选择「Mark Directory as > Excluded」,停止索引该目录。
方案3:清理缓存重启
点击File > Invalidate Caches...,选择「Invalidate and Restart」,让PhpStorm重新生成索引,解决缓存导致的异常显示问题。
内容的提问来源于stack exchange,提问作者Victor
相关产品推荐
相关产品推荐

