Cannot find module ‘../views/HomeView.vue‘ or its corresponding type declarations.ts

在开发Vue3应用时,如果遇到TypeScript无法识别.vue文件的错误,可以通过在根目录下添加env.d.ts声明模块来解决。具体做法是在env.d.ts文件中导入DefineComponent并定义Vue组件,然后在tsconfig.json中确保包含这个声明文件。
摘要由CSDN通过智能技术生成

problem

Cannot find module ‘…/views/HomeView.vue’ or its corresponding type declarations.ts
版本:vue3 ts
请添加图片描述

reason

ts无法识别 vue 文件

solution

在根路径下 env.d.ts 添加以下声明

//  env.d.ts 
// 这个文件生效的前提是 tsconfig.json 中配置了 "include": ["env.d.ts"],
declare module '*.vue' {
  import { DefineComponent } from 'vue';
  // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/ban-types
  const component: DefineComponent<{}, {}, any>;
  export default component;
}
  • 3
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值