ERESOLVE 无法解析依赖树?

时间:2021-05-10 04:47:08

标签: angular npm

当您尝试通过 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.

请帮帮我,我不明白这里需要做什么

2 个答案:

答案 0 :(得分:2)

更新(Angular 12.0.0)

就在我回答几个小时后,Angular 12 发布了 - 它与 NPM 7.13.0 完美配合。

原始答案(Angular 11.2.11)

您使用的是哪个 NPM 版本?

我刚刚在使用版本 7.10.0 时遇到了同样的问题。降级到 6.14.13 后,ng new 按预期工作。

npm i -g npm@6.14.13

目前,如果您想创建一个 Angular 项目,这似乎是最好的解决方案。但是,相应的 Issue on GitHub 已经关闭。所以我希望下一个 Angular 版本也能与最新的 NPM 版本一起使用。

希望能帮到你。

答案 1 :(得分:0)

注意 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,这是 angular angular 在 karma-jasmine-html-reporter@1.6.0 中找到的版本.

然后删除 package-lock.json 文件并运行 npm install