
在 Typescript(ts) + Vue 项目中,路径明明是对的,但却提示找不到模块“./XXX.vue”或其相应的类型声明
这时有几种可能的情况:
-
ts 没有识别 .vue 文件时是模块,需要在
env.d.ts或其它类型声明文件中添加以下内容:declare module "*.vue" { import type { DefineComponent } from "vue"; const component: DefineComponent<{}, {}, any>; export default component; } -
(非常可能遗漏的情况) 该
.vue文件没有声明模块,比如没有声明script标签 或 其没有使用setup选项 或 没有导出组件。
约 282 字...
