當我們使用vite3+typescript創建vue3項目時,在main.ts中報出找不到模塊“./App.vue”或其相應的類型聲明。ts(2307),在ts項目里,.ts文件是識別不了.vue文件的。
解決思路是:
1.在項目的根目錄創建一個env.d.ts文件,必須是.d.ts結尾的,然后再加上如下代碼
declare module "*.vue" {
import type { DefineComponent } from "vue";
const vueComponent: DefineComponent<{}, {}, any>;
export default vueComponent;
}
2.接下來是打開tsconfig.json文件,找到include屬性添加上剛才新建的env.d.ts
