You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Angular升级至19.2.2后使用ChangeDetectionStrategy.OnPush报错求助

Angular 19.1.4升级到19.2.2后ChangeDetectionStrategy类型错误问题解决

将Angular从19.1.4版本升级到19.2.2版本后,在组件中使用changeDetection: ChangeDetectionStrategy.OnPush时出现如下错误:

changeDetection must be a member of ChangeDetectionStrategy enum from @angular/core
Value is of type 'ChangeDetectionStrategy$1'.(-991010)

注:已正确从@angular/core中导入ChangeDetectionStrategy,升级前未出现该错误。

依赖版本变更详情

diff --git a/package.json b/package.json
index 0540c6d..31c4180 100644
--- a/package.json
+++ b/package.json
@@ -16,32 +16,32 @@
     "@angular/common": "^19.0.0",
     "@angular/compiler": "^19.0.0",
     "@angular/core": "^19.0.0",
-    "@angular/forms": "^19.1.4",
+    "@angular/forms": "^19.2.2",
     "@angular/platform-browser": "^19.0.0",
-    "@angular/platform-browser-dynamic": "^19.1.4",
-    "@angular/router": "^19.1.4",
-    "@angular/service-worker": "^19.1.4",
+    "@angular/platform-browser-dynamic": "^19.2.2",
+    "@angular/router": "^19.2.2",
+    "@angular/service-worker": "^19.2.2",
     "rxjs": "~7.8.0",
     "tslib": "^2.3.0"
   },
   "devDependencies": {
-    "@angular-devkit/build-angular": "^19.1.5",
-    "@angular/cli": "^19.1.5",
-    "@angular/compiler-cli": "^19.1.4",
+    "@angular-devkit/build-angular": "^19.2.2",
+    "@angular/cli": "^19.2.2",
+    "@angular/compiler-cli": "^19.2.2",
     "@eslint/css": "^0.1.0",
     "@eslint/js": "^9.17.0",
-    "@typescript-eslint/eslint-plugin": "^8.22.0",
-    "@typescript-eslint/parser": "^8.22.0",
+    "@typescript-eslint/eslint-plugin": "^8.26.1",
+    "@typescript-eslint/parser": "^8.26.1",
     "angular-eslint": "19.0.2",
-    "eslint": "^9.19.0",
-    "globals": "^15.14.0",
-    "ng-packagr": "^19.1.2",
+    "eslint": "^9.22.0",
+    "globals": "^15.15.0",
+    "ng-packagr": "^19.2.0",
     "typescript": "~5.6.2",
     "typescript-eslint": "8.18.0"
   }

已尝试的无效解决方法

  • 降级至19.2.1版本,问题仍存在
  • 执行rm -rf node_modules后重新npm install,问题仍存在
  • 将所有剩余Angular依赖从19.0.0改为19.2.2,问题仍存在

最终解决方案

截至3月12日,本地Visual Studio Code的Angular语言扩展已更新至当时的最新版本,最终确认该错误是由扩展的bug导致。3月13日发布的Angular语言服务扩展新版本已修复此问题,更新扩展即可解决。

内容的提问来源于stack exchange,提问作者Thomas

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.13 22:56:02