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;
}
目录
相关文章
|
9月前
|
前端开发 JavaScript
解决前端报错 Error: Cannot find module ‘xxx‘(包含 uniapp)
解决前端报错 Error: Cannot find module ‘xxx‘(包含 uniapp)
390 0
|
10月前
|
Python
导入名为'materials'的模块时出现了错误
导入名为'materials'的模块时出现了错误
75 2
多model项目下,某个项目引用了公共lib下的service, 其他模块想不受影响的启动解决办法
多model项目下,某个项目引用了公共lib下的service, 其他模块想不受影响的启动解决办法
56 0
|
JavaScript
【ES6】模块化语法(默认、按需导入import导出export的操作)
ES6模块化语法(默认、按需导入导出的操作)
【ES6】模块化语法(默认、按需导入import导出export的操作)
|
PHP
tp5源码解析--自动加载类
在TP5的框架使用过程中,自动加载类是可能会接触到,上手不难,但若想随心所欲的用,还是需要了解一番。用了千次,却没看过一次源码,学习源码,起码对TP5这个框架使用更加得心应手,毕竟技术服务于业务,能够写出更简介、更方便、更有效的业务代码,本身就是一件身心愉悦的事儿;
101 0
|
机器学习/深度学习 算法 C++
python无法导入自定义的包:未解析的引用“Node“
python无法导入自定义的包:未解析的引用“Node“
python无法导入自定义的包:未解析的引用“Node“
|
JavaScript 前端开发
ts重点学习144-描述文件声明
ts重点学习144-描述文件声明
65 0
ts重点学习143-描述文件声明
ts重点学习143-描述文件声明
49 0
ts重点学习143-描述文件声明
“UnwrapRef“ 是一种类型,在同时启用了 “preserveValueImports“ 和 “isolatedModules“ 时,必须使用仅类型导入进行导入。
“UnwrapRef“ 是一种类型,在同时启用了 “preserveValueImports“ 和 “isolatedModules“ 时,必须使用仅类型导入进行导入。
939 0
“UnwrapRef“ 是一种类型,在同时启用了 “preserveValueImports“ 和 “isolatedModules“ 时,必须使用仅类型导入进行导入。
|
Java Android开发
Java工具IDEA创建模块(Module)、如何创建 Module:、如何删除模块
Java工具IDEA创建模块(Module)、如何创建 Module:、如何删除模块
Java工具IDEA创建模块(Module)、如何创建 Module:、如何删除模块