项目执行npm i 报错npm ERR code ERESOLVE

通常情况下,npm install 命令会根据项目中的 package.json 文件来安装所需的依赖项。但有时候,可能会出现一些问题,例如版本冲突或者安装过程中出现警告。

npm 版本问题会导致下载冲突,从而中断安装过程。npm i  下载依赖的时候出现以下类似的报错,大概就是版本的问题。

npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR! 
npm ERR! While resolving: @vue/eslint-config-standard@6.1.0
npm ERR! Found: eslint-plugin-vue@8.7.1
npm ERR! node_modules/eslint-plugin-vue
npm ERR!     dev eslint-plugin-vue@"^8.0.3" from the root project
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! peer eslint-plugin-vue@"^7.0.0" from @vue/eslint-config-standard@6.1.0
npm ERR! node_modules/@vue/eslint-config-standard
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps

......

原因:可能是由于不兼容的依赖版本导致的问题。
解决:在命令后面加上 --force 或 --legacy-peer-deps参数

// 1.清除缓存
npm cache clean

// 若清除缓存时报错 则使用强制清除缓存
npm cache clean --force

/**
 * 若执行 npm cache clean --force 出现:
 * npm WARN using --force Recommended protections disabled.
 * 安装的npm版本过高 说明需要降低npm的版本了
 * 执行 :// 6.14.10 为版本号
 * npm 降低到指定版本:npm install npm@6.14.10 -g  
 * cnpm 降低到指定版本:npm install cnpm@6.14.10 -g 
 */

// 2. 执行安装
npm i --force

例:安装某个插件失败

在命令后面加上 --legacy-peer-deps 参数

总结

--force:表示强制安装,即使存在冲突或警告,也会强制执行安装操作。该参数可以绕过版本冲突或者安装过程中出现警告问题,强制安装依赖项。

--legacy-peer-deps:是在v7中引入的,目的是绕过peerDependency自动安装。它告诉 NPM 忽略项目中引入的各个modules之间的相同modules但不同版本的问题并继续安装,保证各个引入的依赖之间对自身所使用的不同版本modules共存。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值