Search code examples
angularangular-routerpolyfills

Angular 6 router crashes app in all browsers after enabling polyfills?


I have an angular 6 PWA, everything was good and working up until the point I enabled polyfills. Now when I run ngserve and try to navigate to another component it simply errors out and router outlet goes blank.

I have a similar app that works fine and to see if I ruined something with those polyfills - I just copy pasted the polyfills file there and with the same results.

I have also tried to run ng serve --prod but exact same result.

I have also commented out the polyfills except the reflect and zone as those were enabled by default and now the behaviour persists. Don't know what else to try on this one.

ERROR Error: "[object Object]"
resolvePromisehttp://localhost:4200/polyfills.js:7406:31resolvePromisehttp://localhost:4200/polyfills.js:7363:17scheduleResolveOrRejecthttp://localhost:4200/polyfills.js:7465:17invokeTaskhttp://localhost:4200/polyfills.js:7013:17onInvokeTaskhttp://localhost:4200/vendor.js:62603:24invokeTaskhttp://localhost:4200/polyfills.js:7012:17runTaskhttp://localhost:4200/polyfills.js:6780:28drainMicroTaskQueuehttp://localhost:4200/polyfills.js:7187:25invokeTaskhttp://localhost:4200/polyfills.js:7092:21invokeTaskhttp://localhost:4200/polyfills.js:8132:9globalZoneAwareCallbackhttp://localhost:4200/polyfills.js:8158:17 core.js:1673
    defaultErrorLogger
    core.js:1673
    ./node_modules/@angular/core/fesm5/core.js/ErrorHandler.prototype.handleError
    core.js:1719
    next
    core.js:4311:109
    ./node_modules/@angular/core/fesm5/core.js/EventEmitter.prototype.subscribe/schedulerFn<
    core.js:3551:34
    ./node_modules/rxjs/_esm5/internal/Subscriber.js/SafeSubscriber.prototype.__tryOrUnsub
    Subscriber.js:195
    ./node_modules/rxjs/_esm5/internal/Subscriber.js/SafeSubscriber.prototype.next
    Subscriber.js:133
    ./node_modules/rxjs/_esm5/internal/Subscriber.js/Subscriber.prototype._next
    Subscriber.js:77
    ./node_modules/rxjs/_esm5/internal/Subscriber.js/Subscriber.prototype.next
    Subscriber.js:54
    ./node_modules/rxjs/_esm5/internal/Subject.js/Subject.prototype.next
    Subject.js:47
    ./node_modules/@angular/core/fesm5/core.js/EventEmitter.prototype.emit
    core.js:3535:52
    onHandleError/<
    core.js:3842:48
    ./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.invoke
    http://localhost:4200/polyfills.js:6980:17
    ./node_modules/zone.js/dist/zone.js/</Zone.prototype.run
    http://localhost:4200/polyfills.js:6730:24
    ./node_modules/@angular/core/fesm5/core.js/NgZone.prototype.runOutsideAngular
    core.js:3779
    onHandleError
    core.js:3842
    ./node_modules/zone.js/dist/zone.js/</ZoneDelegate.prototype.handleError
    http://localhost:4200/polyfills.js:6984:17
    ./node_modules/zone.js/dist/zone.js/</Zone.prototype.runGuarded
    http://localhost:4200/polyfills.js:6746:25
    _loop_1
    http://localhost:4200/polyfills.js:7269:21
    ./node_modules/zone.js/dist/zone.js/</</api.microtaskDrainDone
    http://localhost:4200/polyfills.js:7278:17
    drainMicroTaskQueue
    http://localhost:4200/polyfills.js:7194:13
    ./node_modules/zone.js/dist/zone.js/</ZoneTask.invokeTask
    http://localhost:4200/polyfills.js:7092:21
    invokeTask
    http://localhost:4200/polyfills.js:8132:9
    globalZoneAwareCallback
    http://localhost:4200/polyfills.js:8158:17

Solution

  • This was due to unsubscribing in a faulty way with onDestroy.

    I was trying to unsubscribe to some subscriptions that I have created but for some odd reason that was erroring out and now that I've fixed this the routerLink works again.