Could not find a declaration file for module ‘XXXXX’

TS7016: Could not find a declaration file for module ‘blueimp-md5’. ‘F:/ZLD/element-admin/node_modules/blueimp-md5/js/md5.js’ implicitly has an ‘any’ type.   Try npm install @types/blueimp-md5 if it exists or add a new declaration (.d.ts) file containing declare module 'blueimp-md5';

以上便是报错的复现结果,在报错最后面已经给出了解决方案,在这里我大概解释一下。今天在用 Vue + Ts 写项目时,需要用到 blueimp-md5 的插件,但是在引入以后报错了。大致原因就是 TS 无法识别 JS 的插件,需要声明一下或者安装 TS 版本的插件,以下是解决方案,建议使用第一种。

解决方案一

在 src 目录下找到 shims-vue.d.ts 文件,如果没有请创建一个 xxx.d.ts 的文件。加入以下代码,即可解决。

declare module 'blueimp-md5'

解决方案二

方案二仅适合有 TS 版本的包,如果没有请使用方案一。

// 示例 npm install @types/blueimp-md5

npm install @types/xxxx

给TA打赏
共{{data.count}}人
人已打赏
其它

Ubuntu中apt与apt-get命令的区别

2020-10-27 22:40:45

前端问答

Cannot find name 'require'. Do you need to install type definitions for node

2020-11-11 9:55:45

0 条回复 A文章作者 M管理员
    暂无讨论,说说你的看法吧
个人中心
购物车
优惠劵
今日签到
有新私信 私信列表
搜索