Visual Studio Code 中的自动导入仅提供 TypeScript 中 Lerna 子包的绝对路径 [英] Auto import in Visual Studio Code only offering absolute path with Lerna subpackages in TypeScript
问题描述
出于某种原因,最近我的 Visual Studio Code 发生了变化,开始只提供从子包级别对我的 Lerna 包进行绝对导入,例如:
For some reason, very recently my Visual Studio Code changed and started only offering absolute imports from the sub-package level with my Lerna packages, for example:
如您所见,自动导入建议文件的 @package/server/src/database
路径,而它应该只是 ../database
作为正在编辑的文件位于同一个包中,并且位于包含我尝试使用的数据库变量的文件下方的一个文件夹中.
As you can see, the auto import is suggesting the @package/server/src/database
path to the file when it should just be ../database
as the file being edited is within the same package and is just one folder below the file containing the database variable I'm trying to use.
这是错误还是配置问题?
Is this a bug or configuration issue?
我已将 Visual Studio Code 中 TypeScript 的 Import Module Specifier
设置设置为所有三个选项(自动、相对和绝对),它们似乎没有任何区别.
I've set my Import Module Specifier
setting for TypeScript in Visual Studio Code to all three options (auto, relative, and absolute) and none of them seem to make any difference.
推荐答案
在 Visual Studio Code 中,菜单 File → Preferences → Settings →用户设置、
In Visual Studio Code, menu File → Preferences → Settings → User Settings,
"typescript.preferences.importModuleSpecifier": "relative"
它对我来说很好用.它进口
It works fine for me. It imports
import { RegistrationComponent } from '../../abc-modules/registration/registration.component';
代替
import { RegistrationComponent } from 'app/abc-modules/registration/registration.component';
这篇关于Visual Studio Code 中的自动导入仅提供 TypeScript 中 Lerna 子包的绝对路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!