vue3 报错提示 找不到模块“./XXX.vue”或其相应的类型声明

vue3 报错提示 找不到模块“./XXX.vue”或其相应的类型声明

从网上找了好多方法比如在tsconfig文件下增加:

{
    "compilerOptions": {
        "baseUrl": "./",
        "paths": {
            "@/*": [
                "src/*"
            ]
        }
    },
    "exclude": [
        "node_modules",
        "dist"
    ]
}

这对我来说根本没有用。
后来看到说可以在src根目录下创建一个后缀为.d.ts的文件,
在这里插入图片描述
写上以下代码:


declare module '*.vue' {
    import type { DefineComponent } from 'vue'
    // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
    const component: DefineComponent<{}, {}, any>
    export default component
  }

问题解决了,不再报模块找不到的错误了

猜你喜欢

转载自blog.csdn.net/Stars_in_rain/article/details/123741249