解决 Vue3 Cannot find module

2,135 阅读1分钟

前言

main.ts 使用组件时,发现 导入的组件报错如下:

cannot find module

解决方法

在目录中创建 shims-vue.d.ts文件里配置, 配置如下:

declare module '*.vue' {
  import { ComponentOptions } from 'vue'
  const componentOptions: ComponentOptions
  export default componentOptions
}

或者点击链接,尤大大在这里有回答。

如果还解决不了

请在 tsconfig.json 添加如下配置:

{
  "compilerOptions": {
    "target": "esnext",
    "module": "esnext",
    "strict": false,
    "jsx": "preserve",
    "moduleResolution": "node"
  }
}