关于cmd中使用npm install axios安装axios报错command failed: npm install --loglevel error的解

619 阅读1分钟

关于cmd中使用npm install axios安装axios报错command failed: npm install --loglevel error的解决方案

当需要使用axios掉接口时,打开终端使用npm install axios -S安装axios时,出现以下报错信息:

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!   dev @vue/eslint-config-standard@"^6.1.0" from the root projectnpm ERR!
npm ERR! Conflicting peer dependency: eslint-plugin-vue@7.20.0
npm ERR! node_modules/eslint-plugin-vue
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
t, or retry
npm ERR! to accept an incorrect (and potentially broken) dependency resolution.
npm ERR!
npm ERR! See C:\Users\47685\node_cache的地址\eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     C:\Users\47685\node_cache的地址\_logs\2022-06-29T07_35_47_562Z-debug-0.log

解决方案:将npm install axios -save改为npm install axios --legacy-peer-deps --save即可成功安装axios
added 5 packages in 4s
表示安装成功,类似的,安装vuex和vue-router也一样,加上–legacy-peer-deps即可

--legacy-peer-deps 作用

在NPM v7中,现在默认安装peerDependencies。

在很多情况下,这会导致版本冲突,从而中断安装过程。

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