Vue 包依赖总结
我在安装依赖包时出现问题:
error minimatch@10.0.3: The engine "node" is incompatible with this module. Expected version "20 || >=22". Got "16.8.0"
这个错误是因为您使用的 Node.js 版本(16.8.0)与 minimatch@10.0.3
包不兼容,该包要求 Node.js 版本 20 或 >=22。
检查具体依赖关系
找出是哪个包依赖了高版本的 minimatch:
yarn why minimatch
我的 package.json 里面没有这个包
"dependencies": {},"devDependencies": {"@ant-design/colors": "^3.2.1","@vue/cli-plugin-babel": "^4.0.4","@vue/cli-plugin-eslint": "^4.0.4","@vue/cli-plugin-router": "^4.0.4","@vue/cli-plugin-vuex": "^5.0.8","@vue/cli-service": "^4.0.4","@vue/compiler-sfc": "^3.2.33","@vue/eslint-config-standard": "^4.0.0","babel-eslint": "^10.0.1","babel-plugin-import": "^1.12.2","babel-plugin-transform-remove-console": "^6.9.4","encryptlong": "^3.1.4","eslint": "^5.16.0","eslint-config-prettier": "^6.10.1","eslint-plugin-html": "^5.0.0","eslint-plugin-vue": "^5.2.3","jsencrypt": "^3.2.1","less": "^3.0.4","opencollective": "^1.0.3","opencollective-postinstall": "^2.0.2","spark-md5": "^3.0.1","vcolorpicker": "^1.1.0","vue-svg-icon-loader": "^2.1.1","vue-template-compiler": "^2.6.14","webpack-theme-color-replacer": "^1.2.17"},
这说明 minimatch@10.0.3
是通过其他间接依赖引入的。
查看完整的依赖链
yarn why minimatch@10.0.3
yarn list --pattern minimatch
查看 @types/minimatch 的依赖关系
# 查看 @types/minimatch 被谁依赖
yarn why @types/minimatch
查看详细的依赖树
# 查看所有包含 minimatch 的包及其依赖关系 yarn list --pattern minimatch --all# 或者查看完整的依赖树 yarn list --depth=5 | grep -A5 -B5 "minimatch@10"
检查 package.json 中的间接依赖
# 查看所有依赖关系 cat yarn.lock | grep -A10 -B10 "minimatch@10.0.3"# 或者更精确地搜索 grep -n "minimatch@10.0.3" yarn.lock
使用 yarn info
# 查看 minimatch@10.0.3 的信息 yarn info minimatch@10.0.3 --json
在package.json中指定版本
"resolutions": {"**/@types/minimatch": "3.0.5","**/minimatch": "3.1.2","**/globby/@types/glob": "8.1.0"}
end.