Unhandled promise rejection: TypeError: Cannot read property 'attachData' of undefined
See original GitHub issueHello!
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.
Any suggestions on how to resolve this? Am I not catching a promise correctly somewhere?
Issue Analytics
- State:
- Created 3 years ago
- Comments:8 (5 by maintainers)
Top 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 >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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…
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
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