为什么 ng new newApp 生成无法解决依赖树错误

Roh*_*h V 20 javascript node.js npm web angular

我正在尝试使用命令创建一个新的 angular 应用程序 ng new app-name.. 但运行该命令后,它在命令行中显示以下内容。

Installing packages (npm)...npm ERR! code ERESOLVE
npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR! 
npm ERR! While resolving: angular-module@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.
npm ERR! 
npm ERR! See /home/vazha/.npm/eresolve-report.txt for a full report.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/vazha/.npm/_logs/2021-05-07T05_12_55_121Z-debug.log
? Package install failed, see above.
The Schematic workflow failed. See above.
Run Code Online (Sandbox Code Playgroud)

我们如何解决这个问题?

小智 33

此错误是由 npm 7 问题引起的。Angular 团队建议暂时使用 npm 6。

运行npm install -g npm@6以确保您使用的是该版本。

另一种方法是ng new使用--skipInstall标志运行,然后使用npm install --legacy-peer-deps.


Nic*_*hin 9

首先像往常一样创建项目:

ng new <project>
Run Code Online (Sandbox Code Playgroud)

然后进入项目目录,将 package.json 中的 jasmine-core 版本修改为“^3.7.1”。然后再次开始安装:

npm install
Run Code Online (Sandbox Code Playgroud)

这是一个临时解决方案,但它有效