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博客

相关推荐
不总是11 小时前
Windows 系统 Node.js 免安装版(zip)安装与配置教程(2026 最新)
前端·windows·node.js
蓝乐18 小时前
Express 知识点总结
node.js·express
kylinmin21 小时前
Node.js安装及环境配置超详细教程(以win11为例子)
node.js
阿奇__21 小时前
基于 Node.js 与智谱 AI 的 RAG 工程实践
人工智能·node.js
hacker_LeeFei1 天前
前端辨识:npx、npm 、pnpm的区别
前端·npm·node.js
草明1 天前
检查 node.js 项目中的漏洞
node.js·漏洞·audit
前端程序猿i1 天前
PM2 使用详解:Node.js 项目后台运行、守护进程、日志与生产部署
node.js·pm2
m0_535817551 天前
从0到1上手Claude Code:Windows安装+88api配置全流程
windows·gpt·node.js·claude·claudecode·88api
大家的林语冰2 天前
Deno 2.8 正式发布,再次超越 Bun,史上最大的次版本升级诞生!
前端·javascript·node.js
hdsoft_huge2 天前
全开源数字孪生系统搭建方案:全套技术文档
vue.js·开源·node.js·echarts·webstorm