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;
}
目录
相关文章
|
2月前
|
JavaScript 前端开发 安全
VITE+TS项目中别名需要分别设置避免冲突
VITE+TS项目中别名需要分别设置避免冲突
|
7月前
|
前端开发 小程序 PHP
laravel5.8(四)引入自定义常量文件及公共函数文件
开发过程中,我们一般会用到一些不会改变,或者改变不是很频繁的值,这样的值我们一般将他们定义成常量。 比如网站根目录,或者分页数,或者域名等等。 那我们如何在laravel5.8中引入自定义的常量文件及公共的函数文件呢。 大概有两种方式: 1:框架目录下引入(不推荐) 在框架目录vendor下新建常量文件const.php,以及公共函数文件function.php 在autoload.php文件中引入。 这种方法是可以的,但是不推荐,框架目录下最好都是框架自己的那些文件,正常来说,框架的文件我们在开发过程中,git是不会进行托管的。 2:在app目录下引入 在bootstrap目录下新建常量文件
45 0
|
12月前
|
Python
导入名为'materials'的模块时出现了错误
导入名为'materials'的模块时出现了错误
90 2
|
11月前
|
前端开发 JavaScript
解决前端报错 Error: Cannot find module ‘xxx‘(包含 uniapp)
解决前端报错 Error: Cannot find module ‘xxx‘(包含 uniapp)
582 0
|
机器学习/深度学习 算法 C++
python无法导入自定义的包:未解析的引用“Node“
python无法导入自定义的包:未解析的引用“Node“
python无法导入自定义的包:未解析的引用“Node“
多model项目下,某个项目引用了公共lib下的service, 其他模块想不受影响的启动解决办法
多model项目下,某个项目引用了公共lib下的service, 其他模块想不受影响的启动解决办法
63 0
ts重点学习143-描述文件声明
ts重点学习143-描述文件声明
55 0
ts重点学习143-描述文件声明
“UnwrapRef“ 是一种类型,在同时启用了 “preserveValueImports“ 和 “isolatedModules“ 时,必须使用仅类型导入进行导入。
“UnwrapRef“ 是一种类型,在同时启用了 “preserveValueImports“ 和 “isolatedModules“ 时,必须使用仅类型导入进行导入。
965 0
“UnwrapRef“ 是一种类型,在同时启用了 “preserveValueImports“ 和 “isolatedModules“ 时,必须使用仅类型导入进行导入。
|
Java Android开发
Java工具IDEA创建模块(Module)、如何创建 Module:、如何删除模块
Java工具IDEA创建模块(Module)、如何创建 Module:、如何删除模块
Java工具IDEA创建模块(Module)、如何创建 Module:、如何删除模块
|
JSON Shell 测试技术
gookit/config - Go应用配置管理,支持多种格式,多文件加载,支持数据合并,解析环境变量名等等
gookit/config - Go应用配置管理,支持多种格式,多文件加载,支持数据合并,解析环境变量名,绑定数据到结构体等等
156 0
gookit/config - Go应用配置管理,支持多种格式,多文件加载,支持数据合并,解析环境变量名等等