简体   繁体   English

Typescript 找不到模块 `./app` 或其对应的类型声明 ts(2307)

[英]Typescript cannot find module `./app` or its corresponding type declarations ts(2307)

Typescript is showing the following error within VSCode in src/main.ts , however when I run the project it runs fine without errors or warnings. Typescript 在src/main.ts的 VSCode 中显示以下错误,但是当我运行项目时,它运行良好,没有错误或警告。

在此处输入图像描述

My tsconfig file is as follows:我的 tsconfig 文件如下:

{
    "compilerOptions": {
        "outDir": "dist",
        "target": "esnext",
        "module": "esnext",
        "moduleResolution": "node",
        "strict": true,
        "jsx": "preserve",
        "sourceMap": true,
        "resolveJsonModule": true,
        "esModuleInterop": true,
        "lib": ["esnext", "dom"],
        "baseUrl": "src",
        "allowJs": true,
        "paths": {
            "@/*": ["./*"],
            "~/*": ["./*"]
        },
        "suppressImplicitAnyIndexErrors": true
    },
    "include": ["src/**/*.ts", "src/**/*.d.ts", "src/**/*.tsx", "src/**/*.vue"],
    "exclude": ["node_modules", "dist"]
}

App.vue is found in src/App.vue the file contents are below App.vue位于src/App.vue文件内容如下

<template>
    <div>
        <!-- <h1 v-if="showModal">HELLO WORLDDNIOAS</h1> -->
        <!-- <SignInModal :show-modal="showModal" /> -->
        <HomePage />
        <!-- <router-view></router-view> -->
    </div>
</template>

<script lang="ts">
import { defineComponent, computed, ref } from "vue";
import HomePage from "@/components/HomePage.vue";
import SignInModal from "@/components/SignInModal.vue";
import Test from "@/components/Test.vue";
import { useStore } from "vuex";

export default defineComponent({
    name: "App",
    components: {
        HomePage,
        SignInModal,
        Test,
    },
    setup() {
        const store = useStore();
        const hello = ref(false);
        return {
            showModal: computed<boolean>(
                () => store.getters["modal/showModal"]
            ),
            hello,
        };
    },
});
</script>

<style>
#app {
    font-family: Avenir, Helvetica, Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    text-align: center;
}
</style>

I've also got type definitions in shims-vue.d.ts as follows:我在shims-vue.d.ts中也有类型定义,如下所示:

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

As mentioned the app loads fine without errors in the console and App.vue displays correctly.如前所述,应用程序在控制台中加载正常且没有错误,并且App.vue正确显示。 Why is VSCode giving me this error?为什么 VSCode 给我这个错误?

Vue 3 doesn't have exported Vue object and the correct module declaration is the following: Vue 3 没有导出Vue object,正确的模块声明如下:

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 TS2307:找不到模块“@/*”或其对应的类型声明 - TS2307: Cannot find module '@/*' or its corresponding type declarations 插件 typescript:@rollup/plugin-typescript TS2307:找不到模块“./App.svelte”或其相应的类型声明 - Plugin typescript: @rollup/plugin-typescript TS2307: Cannot find module './App.svelte' or its corresponding type declarations 业力,Webpack &amp; Typescript:TS2307:找不到模块“log4js”或其相应的类型声明 - Karma, Webpack & Typescript: TS2307: Cannot find module 'log4js' or its corresponding type declarations TS2307:找不到模块“./App.vue”或其相应的类型声明 - TS2307: Cannot find module './App.vue' or its corresponding type declarations Heroku:使用 graphql 文件编译 Typescript 时出错 - 错误 TS2307:找不到模块“graphql”或其相应的类型声明 - Heroku: error compiling Typescript with graphql files - error TS2307: Cannot find module 'graphql' or its corresponding type declarations Lerna with Yarn、TypeScript 和 React Native:找不到模块“@project/common”或其对应的类型 declarations.ts(2307) - Lerna with Yarn, TypeScript and React Native: Cannot find module '@project/common' or its corresponding type declarations.ts(2307) 错误 TS2307:找不到模块“路径”或其相应的类型声明。 尝试使用 Knex 在 heroku 应用程序中迁移时 - error TS2307: Cannot find module 'path' or its corresponding type declarations. when trying to migrate in heroku app with Knex React,Storybook - TS2307:找不到模块“按钮”或其相应的类型声明 CAN SB RESOLVE? - React,Storybook - TS2307: Cannot find module 'Button' or its corresponding type declarations CAN SB RESOLVE? 错误 TS2307:找不到模块或其对应的类型声明。 在 Github 操作 - error TS2307: Cannot find module or its corresponding type declarations. on Github Actions 错误 TS2307:找不到模块“fs”或其相应的类型声明 - error TS2307: Cannot find module 'fs' or its corresponding type declarations
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM