ts解决依赖引入报错:无法找到模块“xxxxxx”的声明文件的报错问题

简介: ts解决依赖引入报错:无法找到模块“xxxxxx”的声明文件的报错问题

依赖引入报错是因为ts没有识别当前引入的依赖,在vite-env.d.ts中声明该依赖即可解决,语法:declare module "依赖名";

declare module "file-saver";


解决找不到模块“./App.vue”或其相应的类型声明。

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


解决router引入报错的问题

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

declare module 'vue-router'

一些依赖报错问题的解决

// <reference types="vite/client" />
// 解决引入vue的报错
declare module "*.vue" {
  import { DefineComponent } from "vue";
  const component: DefineComponent<{}, {}, any>;
  export default component;
}
// 解决引入scss报错问题
declare module "*.scss" {
  const scss: Record<string, string>;
  export default scss;
}
// 解决引入模块的报错提示
declare module "vuedraggable/src/vuedraggable";
declare module "@pureadmin/components";
declare module "@pureadmin/theme";
declare module "@pureadmin/theme/dist/browser-utils";
declare module "nprogress";
declare module "file-saver";
declare module "element-plus/dist/locale/zh-cn.mjs"; /*解决element-plus国际化依赖报错*/
/* 
  解决axios报错:类型“{ params: any; "": any; }”的参数不能赋给类型“AxiosRequestConfig<any>
  解决:属性“xxxxx”在类型”{ $: ComponentInternalInstance; $data : {}; $props:Part......报错问题
  */
declare module "axios" {
  export interface AxiosRequestConfig {
    // 添加数据类型
    handlerEnabled?: boolean;
    baseURL: string;
    timeout: number;
  }
}
// 处理TS数据类型问题  类型“AxiosResponse<any, any>”上不存在属性“meta”。
declare module "axios" {
  interface AxiosResponse<T = any> {
    meta: any;
    // 这里追加你的参数
    baseURL?: string;
    timeout?: number;
  }
  export function create(config?: AxiosRequestConfig): AxiosInstance;
}
目录
相关文章
uniapp 如何封装uni.request请求(登录接口、业务接口)
uniapp 如何封装uni.request请求(登录接口、业务接口)
uniapp 如何封装uni.request请求(登录接口、业务接口)
|
缓存 前端开发 JavaScript
一看就懂的gulp操作指南:让前端工作变得更加轻松(一)
一看就懂的gulp操作指南:让前端工作变得更加轻松
|
缓存 资源调度 JavaScript
server error: Preprocessor dependency “less“ not found. Did you install it?
server error: Preprocessor dependency “less“ not found. Did you install it?
1284 0
|
JavaScript
vue3 vite配置@根路径---解决:找不到模块“./xx/xxx.vue”或其相应的类型声明
vue3 vite配置@根路径---解决:找不到模块“./xx/xxx.vue”或其相应的类型声明
4887 0
Vue3中getCurrentInstance如何与ts结合使用
【8月更文挑战第16天】Vue3中getCurrentInstance如何与ts结合使用
632 2
Vue3中getCurrentInstance如何与ts结合使用
|
缓存 前端开发 JavaScript
React 视频弹幕组件 Video Danmaku
视频弹幕(Danmaku)是在线视频平台中实时显示用户评论的方式,增强互动体验。本文介绍如何在React中实现视频弹幕组件,涵盖基本结构、常见问题及解决方案,如避免弹幕重叠、优化性能、确保同步等,并通过代码示例详细解释。帮助开发者解决样式不一致、输入验证不足和加载延迟等问题,提供实用参考。
711 20
|
JavaScript IDE 开发工具
找不到模块“./App.vue”或其相应的类型声明。ts(2307)
这篇文章介绍了在Vue 3 + TypeScript + Vite开发环境中解决找不到`.vue`文件模块或其类型声明错误的两种方法:使用VSCode的TypeScript Vue Plugin (Volar)插件或手动在`env.d.ts`文件中声明`*.vue`模块类型。
3742 1
找不到模块“./App.vue”或其相应的类型声明。ts(2307)
|
JSON 数据格式
Echarts设置背景的网格线为虚线
Echarts设置背景的网格线为虚线
1112 0
|
前端开发 JavaScript API
开箱即用的axios封装:Vue3+TS(建议收藏)
Axios多用于处理前端项目的Ajax请求,这里要注意区分Axios和Ajax:Ajax是一种技术统称,Axios是第三方库。在使用的时候,我们可以直接使用Axios来发起请求,也可以封装后采用统一的接口发送请求。在前端项目中,应该大多数人都会选择封装一下Axios,不仅可以节省代码,看起来更简洁;而且可以统一管理请求和响应。本文就以Vue3+Typescript,封装一个”开箱即用“的Axios。
12613 6
开箱即用的axios封装:Vue3+TS(建议收藏)
|
前端开发 JavaScript UED

热门文章

最新文章