Loading...

TS2307-Cannot-find-module-‘.-App.vue‘-or-its-corresponding-type-declarations解决办法

阅读 ...

这个错误是 TypeScript(TS)无法识别 .vue 文件模块导致的,原因是 缺少 Vue 相关的类型声明配置。

解决办法:

1.先执行以下命令,确保项目中已安装 Vue 核心依赖和类型声明文件:

1
2
3
# Vue 3 项目
npm install vue@3
npm install -D @vue/tsconfig @vue/runtime-core @types/node

2.添加 Vue 类型声明文件

在项目 src 目录下新建文件 shims-vue.d.ts(文件名固定,TS 会自动识别):

1
2
3
4
5
6
7
// src/shims-vue.d.ts
declare module '*.vue' {
  import type { DefineComponent } from 'vue'
  // 泛型参数:Props类型、Emits类型、Slots类型(默认任意)
  const component: DefineComponent<{}, {}, any>
  export default component
}

如果觉得有帮助,欢迎点赞、关注、转发~

本文由 iamxurulin 原创发布,转载请保留原文链接。
最后更新于 2026-08-23 17:21:42
关于作者与文章

本文为 iamxurulin 原创技术文章。如对内容有疑问或建议,欢迎在评论区交流讨论。

Coder_Studio - 记录后端开发、算法与 AI 的成长之路