vue3 error message prompts that the module "./XXX.vue" or its corresponding type declaration cannot be found

vue3 error message prompts that the module "./XXX.vue" or its corresponding type declaration cannot be found

I found many methods on the Internet, such as adding: under the tsconfig file:

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

This doesn't work for me at all.
Later I saw that you can create a file with the suffix .d.ts in the src root directory and
Insert image description here
write the following code:


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
  }

The problem is solved and the module not found error is no longer reported.

Guess you like

Origin blog.csdn.net/Stars_in_rain/article/details/123741249