question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeError: Cannot read property 'onDestroy' of undefined -- paths to resolution

See original GitHub issue

I don’t want to just submit a patch here for the problem as it would assume developer intent. Let’s see what the problem is.

I’ve traced the bug in one scenario. If you decorate a regular class (not a component) with @UntilDestroyed() (which used to execute silently even if it perhaps should not have ?), instantiate it directly (myVar = new MyClass()) then this call in decorateDeclarable(type, options)

def.onDestroy = decorateNgOnDestroy(def.onDestroy, options);

triggers the error.

If you just want to avoid the error (and keep the buggy assumptions of decorated classes) then the error can be suppressed by bracketing the code:

if (def !== undefined) { def.onDestroy = decorateNgOnDestroy(def.onDestroy, options); markAsDecorated(def); }

and perhaps adding a warning. However the more constructive behaviour might be to synthesize a way to convert that decorated class into something that behaves like a component with its expected onDestroy lifecycle stage.

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7

github_iconTop GitHub Comments

1reaction
cryptobrainscommented, Feb 3, 2021

I love your libraries by the way. Very well thought-out.

1reaction
arturovtcommented, Feb 3, 2021

Glad you’ve resolved the issue!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Cannot Read Property of Undefined in JavaScript - Rollbar
TypeError : Cannot read property of undefined occurs when a property is read or a function is called on an undefined variable.
Read more >
Angular ERROR TypeError: Cannot read properties of ...
I have problem. Angular is sometimes showing error ERROR TypeError: Cannot read properties of undefined (reading 'onDestroy').
Read more >
cannot read properties of undefined (reading 'ondestroy')
Angular ERROR TypeError: Cannot read properties of undefined (reading 'onDestroy') ... I implemented "onDestroy" to all the classes using ngOnDestroy.
Read more >
https://raw.githubusercontent.com/valor-software/n...
... issues:** - ng2-charts doesn't work with newly created angular 10 project ... navigation error occurs - "Cannot read property 'onDestroy' of undefined" ......
Read more >
@angular/core@15.0.4 - jsDocs.io
let routes = [ ... With Ivy, this property is no longer necessary. ... Provide this token to set the default currency code...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found