Recently I upgraded an angular application from anuglar 10 to 13 and after that we faced a console error called,
Cannot read properties of undefined (reading 'onDestroy')
I faced this issue only on the production build, but I was unable to reproduce it in the local build. So, I tried to run the production build locally using the below command
ng serve --configuration=prod
But it was in vain. After running the production build locally, I was unable to see the console error. And the game begins!
The Solution
Upon further debugging I was able to find out in which component it was happening. It was happening in a component where we used @ngneat/transloco library. The library was expecting ngOnDestory function in the component. So, we created an empty ngOnDestroy function,
export class UserComponent implements OnDestroy {
ngOnDestory() {
// Empty ondestroy function to resolve the error
}
}
It’s just a workaround. But I also found the stackoverflow link which mentions different solutions. But in my case these solutions did not work.
Happy Debugging! Cheers!
Leave a Reply