npm版本问题导致的npm install命令报错

npm ERR! code ERESOLVE npm ERR! ERESOLVE unable to resolve dependency tree

npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! Found: [email protected]
npm ERR! node_modules/webpack
npm ERR!   dev webpack@"4.41.5" from the root project
npm ERR!   peer webpack@">=2" from [email protected]
npm ERR!   node_modules/babel-loader
npm ERR!     dev babel-loader@"^8.0.0" from the root project
npm ERR!   2 more (copy-webpack-plugin, css-loader)
npm ERR! 
npm ERR! Could not resolve dependency:
npm ERR! dev mini-css-extract-plugin@"^0.9.0" from the root project
npm ERR! 
npm ERR! Conflicting peer dependency: [email protected]
npm ERR! node_modules/webpack
npm ERR!   peer webpack@"^4.4.0" from [email protected]
npm ERR!   node_modules/mini-css-extract-plugin
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.

原因
ERESOLVE与npm@7有关的问题很常见,因为npm7.x对某些事情比npm6.x更严格。通常,最简单的解决方法是将--legacy-peer-deps标志传递给npm(e.g.,npm i --legacy-peer-deps),或者使用npm@6。

如果这不能立即起作用,也许可以先删除node_modules和package-lock.json。它们将被重新创建。

解决方案
降级npm到6版本

使用npx指定npm的版本

npx -p npm@6 npm i --legacy-peer-deps


————————————————
版权声明:本文为CSDN博主「疯狂的狮子Li」的原创文章,遵循CC 4.0 BY-SA版权协议,转载请附上原文出处链接及本声明。
原文链接:https://blog.csdn.net/weixin_40461281/article/details/115543024

  1. 在Terminal中输入 npm install npm@3 -g 这个命令安装最新的第3版本(3为大版本号)
  2. 找到npm全局安装的路径,我的是: C:\Users\qwt19\AppData\Roaming\npm\node_modules,将这个路径下的 npm包复制一份
  3. 找到 node.js 的安装路径下的node_modules, 我的是: C:\tools\nodejs\node_modules,将第2步中赋值的npm包替换到当前目录即可
  4. 现在输入 npm -v 即可看到最新版的 npm 了

另外一些npm命令

1.获取npm命令所在位置

npm config get prefix

// 我的npm在
“C:\Users\qwt19\AppData\Roaming\npm"


作者:JamesSawyer
链接:https://www.jianshu.com/p/a5ccd1aad62f
来源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

猜你喜欢

转载自blog.csdn.net/m0_50089886/article/details/120007575