解决npm依赖树冲突的方法以及npm ERR! code ERESOLVE错误的解决方案
一、问题描述
在使用ng new myapp --skip-install 构建Angular 项目后,尝试用npm install 安装依赖的时候报了以下错误。
(base) PS C:\Users\Administrator\Desktop\agtest\myapp> npm i
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: myapp@0.0.0
npm ERR! Found: jasmine-core@3.7.1
npm ERR! node_modules/jasmine-core
npm ERR! dev jasmine-core@“~3.7.0” from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer jasmine-core@“>=3.8” from karma-jasmine-html-reporter@1.7.0
npm ERR! node_modules/karma-jasmine-html-reporter
npm ERR! dev karma-jasmine-html-reporter@“^1.5.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.
npm ERR!
npm ERR! See C:\Users\Administrator\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\Administrator\AppData\Local\npm-cache_logs\2024-07-27T17_20_55_922Z-debug-0.log
(base) PS C:\Users\Administrator\Desktop\agtest\myapp>
二、解决办法
npm install --legacy-peer-deps
三、启动测试
ng serve --open