解决vite-plugin-eslint引入type类型报错的问题

无法找到模块“vite-plugin-eslint”的声明文件。“xxxx”隐式拥有 "any" 类型。
There are types at 'xxxxx/index.d.ts', 
but this result could not be resolved when respecting package.json "exports".
The 'vite-plugin-eslint' library may need to update its package.json or typings.ts(7016)

目前看npm包更新时间在一年前,报错原因可能是由于typescript变更导致依赖包package.json不匹配。

看了github上各个大神提出的解决方案,有点看不懂,搞了很久才大致摸索出了,所以分享下
————————————————

思路是使用patch-package修改vite-plugin-eslint包源文件

patch-package具体使用方法可以参考:

【patch-package】修改node_modules下的依赖包源码-CSDN博客

pnpm i patch-package

pnpm patch vite-plugin-eslint

pnpm patch-commit  xxxxx地址
修改内容如下:

1.复制一份index.js 改为 index.cjs

2.修改package.json文件内容

  "main": "./dist/index.cjs",
  "module": "./dist/index.mjs",
  "types": "./dist/index.d.ts",
  "exports": {
     ".": {
      "require": "./dist/index.cjs",
      "import": "./dist/index.mjs",
      "types": "./dist/index.d.ts"
    }
  },
  • 7
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 5
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值