vscode 中的自动导入仅提供 TypeScript 中 lerna 子包的绝对路径
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/52432191/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Auto import in vscode only offering absolute path with lerna subpackages in TypeScript
提问by Anupheaus
For some reason very recently my vs-code changed and started only offering absolute imports from the sub-package level with my Lerna packages, for example:
出于某种原因,最近我的 vs-code 发生了变化,开始只提供来自我的 Lerna 包的子包级别的绝对导入,例如:
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.
正如您所看到的,自动导入建议@package/server/src/database
文件的路径,../database
因为正在编辑的文件位于同一个包中,并且只是包含我正在尝试使用的数据库变量的文件下方的一个文件夹。
Is this a bug or configuration issue?
这是错误还是配置问题?
I've set my Import Module Specifier
setting for TypeScript in vs-code to all three options (auto, relative and absolute) and none of them seem to make any difference.
我已将Import Module Specifier
vs-code 中的 TypeScript 设置设置为所有三个选项(自动、相对和绝对),它们似乎都没有任何区别。
回答by limbo93
On VScode File>Preferences>Settings>User Settings
在VScode 文件>首选项>设置>用户设置
"typescript.preferences.importModuleSpecifier": "relative"
Works fine for me. It imports
对我来说很好用。它进口
import { RegistrationComponent } from '../../abc-modules/registration/registration.component';
in place of
代替
import { RegistrationComponent } from 'app/abc-modules/registration/registration.component';
回答by Florian Wendelborn
I landed here from Google and had the opposite problem. My VSCode always imported the relative path even though it was from a different lerna package. Turns out that I simply forgot to add the package that it was wrongly importing to my consuming package's package.json
.
我从 Google 来到这里,却遇到了相反的问题。我的 VSCode 总是导入相对路径,即使它来自不同的 lerna 包。事实证明,我只是忘记将错误导入的包添加到我的消费包的package.json
.
Now, everything works as expected. Hope this saves someone a few minutes of debugging.
现在,一切都按预期进行。希望这可以为某人节省几分钟的调试时间。