找不到模块“vue”。您的意思是将“moduleResolution”选项设置为“node”,还是将别名添加到“paths”选项?

Pan*_*ode 5 vuejs3

我试图
import { ref } from 'vue'; import { onClickOutside } from '@vueuse/core'; import { useRoute } from 'vue-router'; 从 vue 包导入任何属性,然后收到此错误。

Cannot find module 'vue-router'. Did you mean to set the 'moduleResolution' option to 'node', or to add aliases to the 'paths' option?对于其他对象我也收到此错误Property 'xxxxxx' does not exist on type '{}'.

我添加了"moduleResolution":"node"编译器选项,然后我也遇到了同样的错误。

如何解决这个错误?

LEv*_*145 9

对我有帮助

添加"moduleResolution": "node""compilerOptions"tsconfig.app.json重启VSCode

{
  ...
  "compilerOptions": {
    ...
    "moduleResolution": "node"
  }
}
Run Code Online (Sandbox Code Playgroud)


Tre*_*ree 5

如果您使用的是 vscode,请尝试更改 volar 的 typescript 版本(工作区版本)。command + p然后搜索volar,你可能会看到这样的选项:

更改 volar 的 typescript 版本