报错原因:在执行 npm install 存在依赖冲突。
npm ERR! code ERESOLVE
npm ERR! ERESOLVE could not resolve
npm ERR!
npm ERR! While resolving: compression-webpack-plugin@3.1.0
npm ERR! Found: webpack@3.12.0
npm ERR! node_modules/webpack
npm ERR! peer webpack@"2 || 3 || 4" from babel-loader@7.1.5
npm ERR! node_modules/babel-loader
npm ERR! babel-loader@"^7.1.2" from vue-photo-preview@1.1.3
npm ERR! node_modules/vue-photo-preview
npm ERR! vue-photo-preview@"^1.1.3" from the root project
npm ERR! peer webpack@"^3.1.0" from extract-text-webpack-plugin@3.0.2
npm ERR! node_modules/extract-text-webpack-plugin
npm ERR! extract-text-webpack-plugin@"^3.0.1" from vue-photo-preview@1.1.3
npm ERR! node_modules/vue-photo-preview
npm ERR! vue-photo-preview@"^1.1.3" from the root project
npm ERR! 9 more (file-loader, less-loader, uglifyjs-webpack-plugin, ...)
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer webpack@"^4.3.0 || ^5.0.0" from compression-webpack-plugin@3.1.0
npm ERR! node_modules/compression-webpack-plugin
npm ERR! dev compression-webpack-plugin@"^3.1.0" from the root project
npm ERR!
npm ERR! Conflicting peer dependency: webpack@5.89.0
npm ERR! node_modules/webpack
npm ERR! peer webpack@"^4.3.0 || ^5.0.0" from compression-webpack-plugin@3.1.0
npm ERR! node_modules/compression-webpack-plugin
npm ERR! dev compression-webpack-plugin@"^3.1.0" 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.
解决方案:
使用--force
或--legacy-peer-deps
可解决这种情况。
--force
会无视冲突,并强制获取远端npm库资源,当有资源冲突时覆盖掉原先的版本。--legacy-peer-deps
:安装时忽略所有peerDependencies,忽视依赖冲突,采用npm版本4到版本6的样式去安装依赖,已有的依赖不会覆盖。
建议用--legacy-peer-deps
比较保险一点
在终端重新安装即可解决
npm install --legacy-peer-deps