npm i时报错npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving

简介: npm i时报错npm ERR! code ERESOLVE npm ERR! ERESOLVE could not resolve npm ERR! npm ERR! While resolving

项目场景:


使用npm或yarn安装第三方包。


问题描述


使用npm命令和yarn命令混合使用会出现安装包冲突。


E:\WorkSpace\react\zhuangao_05\dome_01>npm i echarts echarts-for-react
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: @jiaminghi/data-view-react@1.2.5
npm ERR! Found: react@18.2.0
npm ERR! node_modules/react
npm ERR!   peer react@">=16.0.0" from @ant-design/cssinjs@1.3.2
npm ERR!   node_modules/@ant-design/cssinjs
npm ERR!     @ant-design/cssinjs@"^1.3.0" from antd@5.1.2
npm ERR!     node_modules/antd
npm ERR!       antd@"^5.0.4" from the root project
npm ERR!   peer react@">=16.0.0" from @ant-design/icons@4.8.0
npm ERR!   node_modules/@ant-design/icons
npm ERR!     @ant-design/icons@"^4.7.0" from antd@5.1.2
npm ERR!     node_modules/antd
npm ERR!       antd@"^5.0.4" from the root project
npm ERR!     @ant-design/icons@"^4.8.0" from the root project
npm ERR!   53 more (@ant-design/react-slick, @rc-component/portal, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer react@"^16.8.0" from @jiaminghi/data-view-react@1.2.5
npm ERR! node_modules/@jiaminghi/data-view-react
npm ERR!   @jiaminghi/data-view-react@"^1.2.5" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: react@16.14.0
npm ERR! node_modules/react
npm ERR!   peer react@"^16.8.0" from @jiaminghi/data-view-react@1.2.5
npm ERR!   node_modules/@jiaminghi/data-view-react
npm ERR!     @jiaminghi/data-view-react@"^1.2.5" from the root project
npm ERR!
npm ERR! Fix the upstream dependency conflict, or retry
npm ERR! this command with --force, or --legacy-peer-deps
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\86158\AppData\Local\npm-cache\eresolve-report.txt for a full report.
npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\86158\AppData\Local\npm-cache\_logs\2023-01-09T06_13_18_485Z-debug-0.log


原因分析:


如果将yarn.lock和package.lock文件放在一起,有时会变得很困难,因为存在不同步的风险

yarn install 安装生成的 yarn.lock 文件 与 npm install 生成的 package-lock.json 文件时间相差较远,造成了 yarn.lock 的包版本低于 package-lock.json 的包版本。因为以 ?x.x.x 形式定义的包版本在不同时期安装包版本不一致。

yarn 安装 @babel/preset-env 版本有: “7.5.5”, “^7.4.5”,实际安装的 version 是 “7.5.5”。

npm 与 yarn 安装包不一致

纱线和npm是可以互换的。只要你每次都使用相同的一个,它们之间就没有区别。它们有不同的安装目录,这就是它们不能一起使用的原因。Yarn会安装一个包,npm找不到它。npm会安装一个包,yarn找不到它


解决方案:


1、npm i xxx --legacy-peer-deps


使用 npm i xxx --legacy-peer-deps,命令来安装依赖!


为什么?作用?

npm install xxxx --legacy-peer-deps命令与其说是告诉npm要去干什么,不如说是告诉npm不要去干什么。


legacy的意思:遗产/(软件或硬件)已过时但因使用范围广而难以替代的;而npm install xxxx --legacy-peer-deps命令用于绕过peerDependency里依赖的自动安装;它告诉npm忽略项目中引入的各个依赖模块之间依赖相同但版本不同的问题,以npm v3-v6的方式去继续执行安装操作。


所以其实该命令并没有真的解决冲突,而是忽略了冲突,以“过时”(v3-v6)的方式进行下载操作。


2、删除所有关于npm安装依赖的文件


删除之后再重新npm i ,安装需要的第三方包


目录
相关文章
|
2月前
|
网络安全 计算机视觉
【node】 npm install 报错:code 128
【node】 npm install 报错:code 128
78 1
|
18天前
npm ERR! code ERESOLVEnpm ERR! ERESOLVE could not resolvenpm ERR!-解决
npm ERR! code ERESOLVEnpm ERR! ERESOLVE could not resolvenpm ERR!-解决
17 3
|
2月前
使用npm install时遇到问题:npm ERR! code ERESOLVE
使用npm install时遇到问题:npm ERR! code ERESOLVE
|
2月前
npm报错:npm ERR! code ECONNREFUSED npm ERR! errno ECONNREFUSED,npm ERR! npm ERR! If you are behind a
npm报错:npm ERR! code ECONNREFUSED npm ERR! errno ECONNREFUSED,npm ERR! npm ERR! If you are behind a
|
2月前
|
JavaScript Linux 数据安全/隐私保护
node内网安装npm私服以及依赖包上传发布verdaccio
node内网安装npm私服以及依赖包上传发布verdaccio
262 1
|
2月前
|
JavaScript
npm install没问题,但npm run dev的时候报Node Sass version 6.0.1 is incompatible with ^4.0.0 ^5.0.0
npm install没问题,但npm run dev的时候报Node Sass version 6.0.1 is incompatible with ^4.0.0 ^5.0.0
26 0
|
1月前
|
前端开发
windows10 安装node npm 等前端环境 并配置国内源
windows10 安装node npm 等前端环境 并配置国内源
55 3
|
2月前
|
资源调度 JavaScript Linux
nvm, node.js, npm, yarn 安装配置
nvm, node.js, npm, yarn 安装配置
122 1
|
17天前
|
Dart JavaScript 前端开发
npm install node-sass 安装失败的解决方案:利用国内镜像加速安装
npm install node-sass 安装失败的解决方案:利用国内镜像加速安装
108 1
|
18天前
Node历史版本下载及配置npm镜像
Node历史版本下载及配置npm镜像
35 1