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.

Unhandled promise rejection: TypeError: Cannot read property 'attachData' of undefined

See original GitHub issue

Hello!

As I run tests for my Angular app, I am encountering this error Unhandled promise rejection: TypeError: Cannot read property 'attachData' of undefined in components that aren’t using the barcode scanner component I created using this library.

Here’s an example of the error message I am seeing while I run the tests. This is an example where it’s occurring in a component that isn’t using the barcode scanner. image

Any suggestions on how to resolve this? Am I not catching a promise correctly somewhere?

Issue Analytics

  • State:open
  • Created 3 years ago
  • Comments:8 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
ericbladecommented, Aug 16, 2021

right, like I’m curious why Angular is causing it to occur in different parts of the code. Even if it’s being used correctly, is OP structuring something so that Angular would be calling init() and start() several times unexpectedly?

Either way, though, it sounds like it’s probably a good idea to either make start() throw if init() hasn’t been completed, and/or if start() receives a configuration block, then do init() and chain to start() when it’s done…

0reactions
undamaged18commented, Aug 16, 2021

For root cause, Based on what I can see the error is being thrown because the Quagga code can’t find the element it trying to attach to, which is the correct behaviour of the code and I’m not convinced that the issue lies with Quagga without actual code examples from the OP

Noting that this is only speculation, only thing I can think of which would cause what the OP is seeing is they start the camera and then the test moves on to other components of Angular, without more information from the OP not much I could comment on the exact nature of the error

But could be fixed of calling ngOnDestory() to stop() the camera when the component changes and the barcode scanner is no longer being used

  ngOnDestroy() {
    Quagga.stop();
  }

There could also be something in the OP’s code is trying to restart the camera and could be a simple fix by adding some logic to check if the element exists if (this.elRef.nativeElement.querySelector('#camera') !== null) { ... }

Again some comments from the OP would help get to the root cause as I have not been able to replicate the issue other than calling start() outside of the init() callback

Read more comments on GitHub >

github_iconTop Results From Across the Web

'Unhandled Promise rejection:', 'Cannot read properties of ...
angular - 'Unhandled Promise rejection:', 'Cannot read properties of undefined (reading 'then')' - Stack Overflow. Stack Overflow for Teams – ...
Read more >
Msg: Unhandled Promise rejection: Cannot read properties of ...
My angular application has a class which detects network status: @Injectable({ providedIn: 'root' }) export class NetworkAutoSyncService ...
Read more >
TypeError: Cannot read property 'data' of undefined
To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.
Read more >
Unhandled Rejection (TypeError): Cannot read property 'data ...
Unhandled Rejection (TypeError): Cannot read property 'data' of undefined. I am getting this error only when i have a successful login to my ......
Read more >
Unhandled promise rejection TypeError: Cannot read property ...
缺乏对promise的异常处理。原来: getNewToken().then(res => { console.log('[观测点1]',res,resolve) this.request({ url, method, params, ...
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