使用vite创建的vue项目提示:Cannot find module ‘../views/xxxxxx.vue‘ or its corresponding type declarations.

使用vite创建的vue项目提示:Cannot find module '../views/xxxxxx.vue' or its corresponding type declarations.

错误提示

在这里插入图片描述

报错的原因是因为ts不识别.vue后缀的文件。

解决方案

创建脚手架的时候,查看项目的根目录下是否存在了一个env.d.ts文件

1、若存在:修改文件里面的代码,在文件里面增加下面的代码:

declare module "*.vue" {
    
    
    import {
    
     DefineComponent } from "vue"
    const component: DefineComponent<{
    
    }, {
    
    }, any>
    export default component
}

2、若不存在,则在根目录下新建resolveVue.d.ts文件

将上面的代码放在新建的文件中,然后在tsconfig.json的include中增加这个文件名
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/dzdzdzd12347/article/details/130572503