所以今天我想用命令ng new <projectname>创建一个新的Angular 项目,我得到了一个错误:

npm ERR! ERESOLVE unable to resolve dependency tree
npm ERR!
npm ERR! While resolving: project-name@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,重新安装了Angular cli,再次下载并安装了node,npm audit,还有很多其他的东西,但什么都没有发生.

正如你所看到的,error告诉我使用--force这个命令,我try 了,但什么也没发生,而--legacy-peer-deps这个错误是未知选项.

最让我困扰的是,昨晚一切正常,我什么也没做,但今天突然出现了这个错误.

推荐答案

打开用ng new创建的文件夹,然后打开package.json文件.在devDependencies中,将"jasmine core"3.6.0的版本更改为3.8.0,将"karma jasmine html reporter"的版本从1.7.0更改为1.6.0,然后保存它.然后回到终端,回到你的项目,运行npm install.现在它工作了,你可以运行ng serve.

Edit 2021

"jasmine-core": "~3.8.0",
"karma-jasmine-html-reporter": "^1.7.0"

Angular相关问答推荐

Angular 17自定义指令渲染不起作用'

如何在投影项目组周围添加包装元素?

垫-菜单未以17.2.3角显示

HttpInterceptorFn在Angular 17中被忽略

从、管道和映射可观察到的逻辑?

[已解决]如何在模块ngDoBootstrap中测试Angular 自定义元素和做覆盖

使用Angular 13的NgxPrinterService打印时,第二页上的空白区域

在Angular 为17的独立零部件中使用@NGX-平移

react 形式之间的循环关系

Angular14:支持旧版浏览器的官方方式是什么?

Angular keypress 存储空间而不是第一个字母

为什么 Redux 中的对象应该是不可变的?

react表单上的自定义验证器用于密码并确认密码匹配将未定义的参数导入 Angular 4

运行 npm 测试(Angular 2 单元测试)后无法读取未定义的属性 subscribe

Angular 5 国际化

URL 清理导致嵌入式 YouTube 视频的刷新

CORS 错误:requests are only supported for protocol schemes: http…等

如何在Angular中使用带有 td 属性 colspan 的属性绑定?

Angular2 Routerlink:添加查询参数

在渲染视图/模板之前等待 Angular 2 加载/解析模型