Skip to content

The ngOnDestroy handler crashes after upgrade to Angular 11 on 'ng test' (zone.js issue) #40215

@pkwasnik

Description

@pkwasnik

🐞 bug report

Affected Package

The issue is caused by package zone.js

Is this a regression?

Yes, the previous version in which this bug was not present was: Angular 10

Description

After updating Angular to version 11 and using the latest zone.js (0.11.3), on ng test the ngOnDestroy handler crashes throwing:

ERROR Error: Uncaught (in promise): TypeError: Cannot read property 'data-ck-expando' of undefined
TypeError: Cannot read property 'data-ck-expando' of undefined

It is because Object.prototype.toString.call( undefined ) returns [Object Window] instead of [Object Undefined] when the strict mode isn't turned on.

A similar issue was already reporter in the past: #31678

The workaround is to import zone.js in polyfills.js like this import 'zone.js/dist/zone.js' instead of import 'zone.js/dist/zone' or import 'zone.js'

🌍 Your Environment

@angular-devkit/architect       0.1100.4
@angular-devkit/build-angular   0.1100.4
@angular-devkit/core            11.0.4
@angular-devkit/schematics      11.0.4
@schematics/angular             11.0.4
@schematics/update              0.1100.4
ng-packagr                      11.0.3
rxjs                            6.6.3
typescript                      4.0.3
webpack                         4.44.2

Metadata

Metadata

Assignees

Labels

P3An issue that is relevant to core functions, but does not impede progress. Important, but not urgentarea: zonesIssues related to zone.jsstate: confirmed

Type

No type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions