查看: 110|回复: 1

npm安装cz-customizable报错ERESOLVE:peer dependency冲突解决

[复制链接]
发表于 3 小时前 | 显示全部楼层 |阅读模式
在Vue项目中使用commitizen规范Git提交信息时,通常需要安装cz-customizable插件来定制提交格式。但执行npm i cz-customizable@6.3.0 --save-dev后,可能遇到如下报错:
  1. npm ERR! code ERESOLVE
  2. npm ERR! ERESOLVE could not resolve
  3. npm ERR!
  4. npm ERR! While resolving: @vue/eslint-config-standard@6.1.0
  5. npm ERR! Found: eslint-plugin-vue@8.7.1
  6. npm ERR! node_modules/eslint-plugin-vue
  7. npm ERR!   dev eslint-plugin-vue@"^8.0.3" from the root project
  8. npm ERR!
  9. npm ERR! node_modules/@vue/eslint-config-standard
  10. npm ERR!   dev @vue/eslint-config-standard@"^6.1.0" from the root project
  11. npm ERR!
  12. npm ERR! Conflicting peer dependency: eslint-plugin-vue@7.20.0
  13. npm ERR! node_modules/eslint-plugin-vue
  14. npm ERR!   peer eslint-plugin-vue@"^7.0.0" from @vue/eslint-config-standard@6.1.0
  15. npm ERR!   node_modules/@vue/eslint-config-standard
  16. npm ERR!     dev @vue/eslint-config-standard@"^6.1.0" from the root project
  17. npm ERR!
  18. npm ERR! Fix the upstream dependency conflict, or retry
  19. npm ERR! this command with --force, or --legacy-peer-deps
  20. npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
复制代码

该错误本质是peer dependency冲突:项目中已安装了eslint-plugin-vue 8.7.1,而@vue/eslint-config-standard@6.1.0需要peer依赖eslint-plugin-vue@^7.0.0,两者不兼容导致npm无法自动解析依赖树。

解决办法有两种:

1. 使用--legacy-peer-deps参数,让npm忽略严格的peer依赖检查,沿用旧的依赖解析逻辑:
  1. npm i cz-customizable@6.3.0 --save-dev --legacy-peer-deps
复制代码

2. 使用--force参数强制安装,但可能导致其他依赖运行时出错(不推荐,除非明确知道后果)。

推荐采用--legacy-peer-deps,这是npm v7+引入严格peer依赖检查后,为兼容旧项目设计的安全降级方案。

完成安装后,cz-customizable即可正常工作。至于eslint-plugin-vue的版本冲突,可后续单独升级对应的eslint配置包来解决,但不影响当前commitizen的功能。
回复

使用道具 举报

发表于 2 小时前 | 显示全部楼层

Re: npm安装cz-customizable报错ERESOLVE:peer dependency冲突解决

感谢楼主的详细分享!这个错误确实很典型,特别是npm v7以后对peer依赖的检查变严了。`--legacy-peer-deps`确实是当前场景下最实用的解决方案,既不影响项目现有依赖,又能让cz-customizable顺利安装。我之前也踩过类似的坑,这么处理完再配合commitizen用起来就很顺畅了。后面eslint相关的依赖可以等有空再统一升级,不急着改。
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

指导单位

江苏省公安厅

江苏省通信管理局

浙江省台州刑侦支队

DEFCON GROUP 86025

Hacking Group 021A

旗下站点

态势感知中心

应急响应中心

红盟安全

联系我们

官方QQ群:112851260

官方邮箱:security#ihonker.org(#改成@)

官方核心成员

关注微信公众号

Archiver|手机版|小黑屋| ( 沪ICP备2021026908号 )

GMT+8, 2026-6-12 18:00 , Processed in 0.034458 second(s), 18 queries , Gzip On, Redis On.

Powered by ihonker.com

Copyright © 2015-现在.

  • 返回顶部