昨天,我正在开发的一个Angular网站项目涉及到了Cookie技术,于是我像往常那样安装CookieService:
npm install ngx-cookie-service结果你猜怎么着,“这套复杂的生态系统” 随时随地的给你来一顿暴击:
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: my-project-name@0.0.0
npm error Found: @angular/common@19.2.14
npm error node_modules/@angular/common
npm error @angular/common@"^19.0.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer @angular/common@"^20.0.0" from ngx-cookie-service@20.0.1
npm error node_modules/ngx-cookie-service
npm error ngx-cookie-service@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry
npm error this command with --force or --legacy-peer-deps
npm error to accept an incorrect (and potentially broken) dependency resolution.我从这些错误里面看到了一个关键字:20.0.1,没错,如果你这几天在街上溜达,你一定听说了“他们”打算放出Angular 20,但是我没有想到这么快。我随即转到“亮闪闪”网站,果然,V20已经在那里等着我们升级了:

我早就看不惯provideExperimentalZonelessChangeDetection这东西,所以一不做二不休干脆升级我的项目,这样我的欧洲用户就可以使用cookie了。我先把系统安装的Angular CLI从19升级到了20,然后按照这个隐藏的很深的 Update Guide 升级了我项目的Angular CLI。
然后我就有时间写这篇文章了。
我已经顾不上小小的CookieService,因为我项目的整个PromeNG开始罢工,因为它依然依赖19.x.x。为了验证这一点我用Angular 20创建了一个全新的项目,没有用我初级程序员的手触碰任何代码,只是小心的尝试安装PrimeNG,然后得到以下暴击:
npm install primeng @primeng/themes
npm error code ERESOLVE
npm error ERESOLVE unable to resolve dependency tree
npm error
npm error While resolving: my-project-name@0.0.0
npm error Found: @angular/common@20.0.0
npm error node_modules/@angular/common
npm error @angular/common@"^20.0.0" from the root project
npm error
npm error Could not resolve dependency:
npm error peer @angular/common@"19.2.14" from @angular/animations@19.2.14
npm error node_modules/@angular/animations
npm error peer @angular/animations@"^19.0.0" from primeng@19.1.3
npm error node_modules/primeng
npm error primeng@"*" from the root project
npm error
npm error Fix the upstream dependency conflict, or retry我一直以为这个世界是由一些天才维护运转的,自己只需要按照readme.txt和install.txt操作就行了,但是显然不是。我现在twitter上搜索Angular 20 + PrimeNG,搜到了很多庆祝的消息。然后我又尝试搜了下PrimeNG:

当我看到 A couple of Weeks 的时候我要哭了。当然请允许我借此机会感谢PrimeNG这个绝佳的产品,让我在除了Angular Material之外还有更好的选择。
现在我的项目没有办法继续开发,甚至没有办法ng serve…
因此我不得不干一件非常不喜欢的事情,那就降级。
如果你也不幸遇到了这类问题,下面是如何把你的Angular降级到19.x.x。请注意我们只需要降级项目自身的Angular版本即可,不需要降级系统安装的Angular 20.
- 打开项目里面的package.json文件
- 找到 ^20.0.0,把它们修改为 ^19.0.0,这会允许项目使用任何 19.x.x 版本
- 删除package-lock.json文件
- 删除或改名 node_modules 目录
- 重新安装依赖:
npm install
如果你运气不是太差,你的项目将重新降级为19.x.x。
至于勤奋的NGX Cookie Service,只需要在安装的时候指定它的上一个版本好就好了:
npm view ngx-cookie-service versions
[
'1.0.0', '1.0.1', '1.0.3', '1.0.4',
'1.0.5', '1.0.6', '1.0.7', '1.0.8',
'1.0.9', '1.0.10', '2.0.0', '2.0.1',
'2.0.2', '2.1.0', '2.2.0', '2.3.0',
'2.4.0', '3.0.0', '3.0.1', '3.0.2',
'3.0.3', '3.0.4', '3.1.1', '3.1.2',
'3.1.3', '10.0.0', '10.0.1', '10.1.1',
'11.0.0', '11.0.1', '11.0.2', '12.0.0',
'12.0.1', '12.0.2', '12.0.3', '12.1.0-rc.0',
'12.1.0-rc.1', '12.1.0-rc.2', '12.1.0-rc.3', '12.1.0-rc.4',
'12.1.0-rc.5', '13.0.0', '13.0.1', '13.1.0-rc.1',
'13.1.0', '13.1.1', '13.1.2-rc.1', '13.1.2',
'13.2.0-rc.1', '13.2.0', '13.2.1', '14.0.0-rc.0',
'14.0.0-rc.1', '14.0.0-rc.2', '14.0.0', '14.0.1',
'15.0.0-rc.1', '15.0.0-rc.2', '15.0.0-rc.3', '15.0.0',
'16.0.0-rc.0', '16.0.0', '16.0.1', '16.0.2',
'16.1.0', '17.0.0-next.0', '17.0.0-next.1', '17.0.0-next.2',
'17.0.0-rc.0', '17.0.0-rc.1', '17.0.0-rc.2', '17.0.0-rc.3',
'17.0.0', '17.0.1-rc.1', '17.0.1', '17.1.0-rc.1',
'17.1.0', '18.0.0-next.1', '18.0.0-rc.0', '18.0.0',
'19.0.0-next.1', '19.0.0-rc.2', '19.0.0', '19.1.0',
'19.1.2', '20.0.0', '20.0.1'
]
npm install ngx-cookie-service-ssr@19.1.2
added 2 packages, and audited 592 packages in 31s
愿世界和平 🚀。