当您试图通过angular cli创建一个angular项目时,您会得到以下错误
npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: animation@0.0.0
npm ERR! Found: jasmine-core@3.6.0
npm ERR! node_modules/jasmine-core
npm ERR! dev jasmine-core@"~3.6.0" from the root project
npm ERR!
npm ERR! Could not resolve dependency:
npm ERR! peer jasmine-core@">=3.7.1" from karma-jasmine-html-reporter@1.6.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.
请帮帮我,我不明白这里需要做什么
更新(Angular 12.0.0(
就在我回答的几个小时后,Angular 12发布了——它与NPM7.13.0
完美配合。
原始答案(Angular 11.2.11(
您正在使用哪个NPM版本?
我刚刚在使用7.10.0
版本时遇到了同样的问题。降级为6.14.13
后,ng new
正常工作。
npm i -g npm@6.14.13
目前,如果你想创建一个Angular项目,这似乎是最好的解决方案。然而,GitHub上的各个问题已经关闭。因此,我预计Angular的下一个版本也将使用最新的NPM版本。
我希望我能帮助你。
虽然降级到旧版本的npm是可行的,但我不建议这样做,因为他们更新它是有原因的。
新版本可以包含安全漏洞的关键补丁,也可以包含新的或增强的功能。
因此,这里是我的解决方案:
注意angular所说的:
npm ERR! Could not resolve dependency:
npm ERR! peer jasmine-core@">=3.7.1" from karma-jasmine-html-reporter@1.6.0
因此,您需要打开package.json
文件,并将jasmine-core
版本从3.6.0
更改为3.7.1
,这是在karma-jasmine-html-reporter@1.6.0
中找到的角度。
然后删除package-lock.json
文件并运行npm install
。