You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何消除npm install时出现的peer依赖缺失警告?

如何消除npm install时的ESLint peer依赖警告?

嘿,我来帮你搞定这个npm警告的问题!首先咱们先搞清楚警告的原因:

npm WARN eslint-config-react-app@2.1.0 requires a peer of eslint-plugin-jsx-a11y@^5.1.1 but none is installed. You must install peer dependencies yourself.

这个警告是因为你的项目里,react-scripts@1.1.4自带的eslint-config-react-app@2.1.0,要求搭配版本为^5.1.1的eslint-plugin-jsx-a11y,但你手动安装的eslint-plugin-jsx-a11y是6.0.3,版本不匹配导致了peer依赖冲突。

看你提供的package.json,确实在devDependencies里装了更高版本的eslint-plugin-jsx-a11y,这就是问题所在。下面给你两种靠谱的解决办法:

方法一:安装符合要求的依赖版本

直接安装eslint-config-react-app@2.1.0要求的eslint-plugin-jsx-a11y版本,覆盖当前的高版本:

npm install eslint-plugin-jsx-a11y@^5.1.1 --save-dev

执行完这个命令后,再跑npm install,警告就会消失了。

方法二:升级react-scripts到兼容高版本依赖的版本

更高版本的react-scripts对应的eslint-config-react-app已经支持eslint-plugin-jsx-a11y@6.x版本了,你可以直接升级react-scripts:

npm install react-scripts@latest --save

升级完成后,peer依赖的版本要求就会和你当前安装的eslint-plugin-jsx-a11y@6.0.3匹配,警告自然就没了。

额外提示

如果你只是临时想忽略警告,也可以用npm install --legacy-peer-deps命令,但这只是权宜之计,不推荐长期使用,因为可能会掩盖潜在的兼容性问题。

内容的提问来源于stack exchange,提问作者Ralph David Abernathy

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 04:14:04