报错:找不到模块“./App.vue”或其相应的类型声明。
原因:typescript只能理解.ts文件,无法理解.vue文件。
解决:在src/env.d.ts下添加:
/// <reference types="vite/client" />
// 三斜线引用告诉编译器在编译过程中用types形式引入的额外的文件vite/client.d.ts,
// 此文件里面是vite帮我们定义的各种常用类型定义,比如css,图片等。declare module '*.vue' {import type { DefineComponent } from 'vue'// eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-typesconst component: DefineComponent<{}, {}, any>export default component
}
或安装Vue - Official
插件:
参考:
vue.js - vue3+ts,在ts文件中导入vue文件,会报类似的错误:找不到模块“./App.vue”或其相应的类型声明 - 个人文章 - SegmentFault 思否
找不到模块“./App.vue”或其相应的类型声明。ts(2307)-阿里云开发者社区