Node.js 版本兼容问题:minimatch@10.0.3和minio@7.0.28 冲突的解决

我们在构架项目时候,经常会遇到依赖包因当前 Node.js 环境不兼容的问题。比如像我当前的项目,是使用公司开发的框架的写的,要求install安装依赖包必须使用node18环境,然后run start使用node16环境运行。所以没办法,只能使用node18来install依赖包,但是这个minimatch在node18下不适配,安装失败。

javascript 复制代码
error minimatch@10.0.3: The engine "node" is incompatible with this module.
Expected version "20 || >=22". Got "18.20.5"

error minio@7.0.28: The engine "node" is incompatible with this module. 
Expected version ">8  <=18". Got "22.16.0"

最终果断选择降低minimatch@10.0.3的版本,降到了"minimatch": "9.0.5"。

javascript 复制代码
package.json中的resolutions对象里面
  "resolutions": {
    "@terrestris/base-util": "1.0.1",
    "@terrestris/ol-util": "10.2.0",
    "@terrestris/react-geo": "22.4.0",
    "commander": "12.0.0",
    "minimatch": "9.0.5"
  },

yarn 就会强制所有依赖链中对 minimatch 的使用都是 9.0.5这个版本。

如果你使用的npm,需要你这么做:

javascript 复制代码
npm install npm-force-resolutions --save-dev

然后,在 package.json 中添加一个预安装脚本和 resolutions 配置:

javascript 复制代码
package.json文件
  "scripts": {
    "preinstall": "npx npm-force-resolutions"
  },
  "resolutions": {
    "minimatch": "9.0.5"
  }

如果 npm 大于 8.3 可以利用 overrides 直接指定依赖包应该使用的版本:

javascript 复制代码
package.json文件
  "overrides": {
    "minimatch": "9.0.5"
  }

想要看更详细的可以去看这个博主:解决 Node.js 版本不兼容问题:设置 resolutions 强制使用兼容版本的 minimatch。error minimatch@10.0.3: The engine "node"...._minimatch包作用-CSDN博客

相关推荐
金梦人生1 天前
🔥Knife4j vs Swagger:Node.js 开发者的API文档革命!
前端·node.js
Ya-Jun1 天前
快应用TypeError: The ‘compilation‘ argument must be an instance of Compilation错误
node.js·ux·js
亮子AI1 天前
【npm】npm install 产生软件包冲突怎么办?(详细步骤)
前端·npm·node.js
Q_Q5110082851 天前
python+uniapp基于微信小程序的心理咨询信息系统
spring boot·python·微信小程序·django·flask·uni-app·node.js
浪裡遊1 天前
MUI组件库与主题系统全面指南
开发语言·前端·javascript·vue.js·react.js·前端框架·node.js
梵得儿SHI1 天前
Vue 开发环境搭建全指南:从工具准备到项目启动
前端·javascript·vue.js·node.js·pnpm·vue开发环境·nvm版本管理
郏国上2 天前
图片上传阿里云
阿里云·node.js·云计算
tryCbest2 天前
Linux使用Docker部署Node.js+Express+SQLite项目
docker·centos·node.js
GISer_Jing2 天前
LLM对话框项目技术栈&重难点总结
前端·ai·node.js
用户2519162427112 天前
Node之单表基本查询
前端·javascript·node.js