【问题标题】:EXCEPTION: TypeError: Cannot set property 'message' of undefined例外:类型错误:无法设置未定义的属性“消息”
【发布时间】:2017-01-13 21:05:01
【问题描述】:

在旧的 Angular 2 项目上升级许多依赖项后,我在运行时遇到以下错误:

EXCEPTION: TypeError: Cannot set property 'message' of undefined
ErrorHandler.handleError @ error_handler.js:50
(anonymous) @ application_ref.js:259
ZoneDelegate.invoke @ zone.js:242
onInvoke @ ng_zone.js:269
ZoneDelegate.invoke @ zone.js:241
Zone.run @ zone.js:113
(anonymous) @ zone.js:520
ZoneDelegate.invokeTask @ zone.js:275
onInvokeTask @ ng_zone.js:260
ZoneDelegate.invokeTask @ zone.js:274
Zone.runTask @ zone.js:151
drainMicroTaskQueue @ zone.js:418
zone.js:405Unhandled Promise rejection: TypeError: Cannot set property 'message' of undefined
    at ViewWrappedError.set [as message] (errors.js:43)
    at ViewWrappedError.ZoneAwareError (zone.js:683)
    at ViewWrappedError.BaseError [as constructor] (errors.js:26)
    at ViewWrappedError.WrappedError [as constructor] (errors.js:88)
    at new ViewWrappedError (errors.js:73)
    at CompiledTemplate.proxyViewClass.DebugAppView._rethrowWithContext (view.js:650)
    at CompiledTemplate.proxyViewClass.DebugAppView.create (view.js:550)
    at CompiledTemplate.proxyViewClass.View_AppComponent0.createInternal (component.ngfactory.js:125)
    at CompiledTemplate.proxyViewClass.AppView.create (view.js:95)
    at CompiledTemplate.proxyViewClass.DebugAppView.create (view.js:547)
    at CompiledTemplate.proxyViewClass.View_AppComponent_Host0.createInternal (host.ngfactory.js:26)
    at CompiledTemplate.proxyViewClass.AppView.createHostView (view.js:108)
    at CompiledTemplate.proxyViewClass.DebugAppView.createHostView (view.js:564)
    at ComponentFactory.create (component_factory.js:226)
    at ApplicationRef_.bootstrap (application_ref.js:586) ; Zone: <root> ; Task: Promise.then ; Value: TypeError: Cannot set property 'message' of undefined
    at ViewWrappedError.set [as message] (errors.js:43)
    at ViewWrappedError.ZoneAwareError (zone.js:683)
    at ViewWrappedError.BaseError [as constructor] (errors.js:26)
    at ViewWrappedError.WrappedError [as constructor] (errors.js:88)
    at new ViewWrappedError (errors.js:73)
    at CompiledTemplate.proxyViewClass.DebugAppView._rethrowWithContext (view.js:650)
    at CompiledTemplate.proxyViewClass.DebugAppView.create (view.js:550)
    at CompiledTemplate.proxyViewClass.View_AppComponent0.createInternal (component.ngfactory.js:125)
    at CompiledTemplate.proxyViewClass.AppView.create (view.js:95)
    at CompiledTemplate.proxyViewClass.DebugAppView.create (view.js:547)
    at CompiledTemplate.proxyViewClass.View_AppComponent_Host0.createInternal (host.ngfactory.js:26)
    at CompiledTemplate.proxyViewClass.AppView.createHostView (view.js:108)
    at CompiledTemplate.proxyViewClass.DebugAppView.createHostView (view.js:564)
    at ComponentFactory.create (component_factory.js:226)
    at ApplicationRef_.bootstrap (application_ref.js:586) undefined
consoleError @ zone.js:405
_loop_1 @ zone.js:434
drainMicroTaskQueue @ zone.js:438
zone.js:407ZoneAwareError {message: "Uncaught (in promise): TypeError: Cannot set prope…p (http://localhost:4200/main.bundle.js:47366:57)", originalStack: "Error: Uncaught (in promise): TypeError: Cannot se… (http://localhost:4200/main.bundle.js:130849:35)", zoneAwareStack: "Error: Uncaught (in promise): TypeError: Cannot se…localhost:4200/main.bundle.js:130849:35) [<root>]", stack: "Error: Uncaught (in promise): TypeError: Cannot se…localhost:4200/main.bundle.js:130849:35) [<root>]", rejection: TypeError: Cannot set property 'message' of undefined
    at ViewWrappedError.set [as message] (http……}

我尝试在我的所有应用程序(其中包含大约 20 个组件)中搜索 .message 并发现我使用 this.message 属性的结果很少,我确定问题不是来自那里。

我试图将几乎所有的模块和组件一个一个地移除,但找不到修复它的方法。

我的 package.json:

{
  "name": "myapp",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "2.2.1",
    "@angular/compiler": "2.2.1",
    "@angular/core": "2.2.1",
    "@angular/forms": "2.2.1",
    "@angular/http": "2.2.1",
    "@angular/material": "^2.0.0-alpha.11-3",
    "@angular/platform-browser": "2.2.1",
    "@angular/platform-browser-dynamic": "2.2.1",
    "@angular/router": "3.2.3",
    "@ng-bootstrap/ng-bootstrap": "^1.0.0-alpha.15",
    "@types/hammerjs": "^2.0.32",
    "angular2-moment": "^1.0.0",
    "angular2-notifications": "^0.4.47",
    "core-js": "^2.4.1",
    "dragula": "^3.7.1",
    "hammerjs": "^2.0.8",
    "ng2-bootstrap": "^1.1.16-7",
    "ng2-dnd": "^2.0.1",
    "ng2-dragula": "^1.2.0",
    "ng2-select": "^1.1.2",
    "rxjs": "5.0.0-rc.4",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.7.2"
  },
  "devDependencies": {
    "@angular/compiler-cli": "2.2.1",
    "@types/jasmine": "2.5.38",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.20-4",
    "codelyzer": "~2.0.0-beta.1",
    "jasmine-core": "2.5.2",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.9",
    "ts-node": "1.2.1",
    "tslint": "^4.0.2",
    "typescript": "~2.0.3",
    "webdriver-manager": "10.2.5"
  }
}

有人知道如何更有效地定位此错误的来源吗?

【问题讨论】:

  • 你见过这个问题吗? stackoverflow.com/questions/41247165/…
  • 不。但它似乎相关。我会尝试降级区域js
  • 我最近在处理嵌入时看到了这个错误消息。检查组件中的 templateRef 和 html 中的 &lt;template&gt;
  • 昨天突然出现这个错误,完全不知道是什么原因,也回到了zone.js 0.6.26
  • 今天早上我用一个类似的包文件遇到了这个问题,但是降级区并没有立即解决我遇到的问题。就我而言,我已将 template 属性设置为模板的 url,而不是 templateUrl 属性。解决此问题后,我在 0.7.2 区域内一切正常。

标签: angular


【解决方案1】:

这是 zone.js 包的问题,​​导致控制台无法显示实际错误! 尝试降级 zone.js:

npm install --save zone.js@0.7.4

【讨论】:

  • 你刚刚为我节省了几个小时。谢谢!
  • 它也解决了我的问题!谢谢! zonejs 是说没有为链中的每个“然后”处理承诺。即使我在链条的末端也遇到了问题。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-10-14
  • 1970-01-01
  • 2014-04-14
  • 2022-01-01
相关资源
最近更新 更多