VSCode 使用相对路径导入节点模块 [英] VSCode import node modules with relative paths

查看:64
本文介绍了VSCode 使用相对路径导入节点模块的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我以某种方式让我的工作区进入了一种状态,其中 VSCode 提供使用模块 @types 的相对路径为节点模块添加导入:

I've somehow gotten my workspace into a state where VSCode is offering to add imports for node modules using the relative path to the module's @types:

它在我们添加 paths(如此处所述)时开始,但恢复这些更改似乎没有帮助(即使在重新加载 TS 项目"甚至重新加载 VS Code 之后).

It started when we added paths (as described here), but reverting those changes doesn't seem to help (even after a "Reload TS Project" or even reload of VS Code).

对可能导致这种情况的原因有任何想法吗?

Any thoughts on what might be causing this?

VSCode 的导入模块说明符"设置为 auto

VSCode's "Import Module Specifier" is set to auto

推荐答案

如果您的工作区使用的是 Typescript 2.9.2 那么可能是这个问题:

If your workspace is using Typescript 2.9.2 then it may be this issue:

https://github.com/Microsoft/vscode/issues/53597

您可以在右下角的底部栏中看到打字稿的版本.如果您点击它,您将看到您已经拥有的 TS 版本.

You can see the version of typescript in the lower right bottom bar. If you click on it, you will see the versions of TS that you already have available to you.

查看打字稿版本

建议的解决方法是将您的工作区使用的 TypeScript 版本降级到 2.7.2.或者升级到 typescript@next

The suggested workaround is to downgrade the version of TypeScript that your workspace uses to 2.7.2. or to upgrade to typescript@next

关闭此错误的微软工程师表示:

The Microsoft engineer that closed this bug stated:

这已经已在 VS Code 内部人员中修复.在当前版本的 VS Code 上,您可以还要升级您的工作区以使用 Typescript 3.0.我们没有向后移植由于缺乏测试、工程成本和担忧而导致的修复导致其他回归.

This has been fixed in VS Code insiders. On the current version of VS Code, you can also upgrade your workspace to use Typescript 3.0. We did not backport the fix due to lack of testing, engineering cost, and concerns about causing other regressions.

此外,我已经测试将 2.7.2 和 typescript@next 安装到我的本地 node_modules 中.两者都解决问题.

Also, I have tested installing both 2.7.2 and typescript@next into my local node_modules. Both solve the problem.

我希望这会有所帮助!

这篇关于VSCode 使用相对路径导入节点模块的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆