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.

Failed to run demo: Cannot read property 'ImageWrapper' of undefined

See original GitHub issue

I’m trying to run this demo in React, but always got error:

image

import React, { useState, FC, useRef, useEffect, isValidElement } from "react";

import { QuaggaJSStatic } from "@ericblade/quagga2";
import QuaggaLib from "@ericblade/quagga2/lib/quagga";

let Quagga: QuaggaJSStatic = QuaggaLib;

let BarcodeArea: FC<{}> = (props) => {
  let videoElementRef = useRef<HTMLDivElement>(null);

  useEffect(() => {
    Quagga.init(
      {
        inputStream: {
          type: "LiveStream",
          target: videoElementRef.current,
          constraints: {
            width: 400,
            height: 400,
          },
        },
        locate: false,
        numOfWorkers: 2,
        frequency: 10,
        decoder: {
          readers: ["code_128_reader"],
        },
      },
      (err) => {
        if (err) {
          console.error(err);
          return;
        }

        console.log("started");
        Quagga.start();
      }
    );

    Quagga.onDetected((result) => {
      console.log("detect", result);
    });

    Quagga.onProcessed((result) => {
      console.log("process", result);
    });

    return () => {
      Quagga.stop();
    };
  }, []);

  return <div className={styleVideo} ref={videoElementRef}></div>;
};

Also I tried to run the demo at http://localhost:8080/example/live_w_locator.html by fixing the paths and adding Quagga = quagga.default. Turned out the problem remains.

Is there a fix for that?

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:21 (10 by maintainers)

github_iconTop GitHub Comments

1reaction
ericbladecommented, Dec 31, 2019

i’m not convinced that with the current structure of the worker, that there’s even any benefit to it – it just ran multiple copies of itself configured the same way, across multiple threads. A restructuring of it might perhaps run different decoders on different worker threads.

I’ve published 0.0.13, if you want to try that and see if it fixes the issue. I’m going to close this one anyway, in favor of the all-encompassing “restructuring things is really needed”, but if this persists, lmk… i didn’t see it in my quick test (i did look at the console output this time 😄 )

1reaction
ericbladecommented, Dec 31, 2019

figured it out, it’s the removal of the webpack-plugins\umd.js file that was removed as part of the upgrade to webpack from v2 to v5. i… don’t think that can be directly put back in, but i think we’ll need to study it. it would put the entire source of the quagga.js module into the factorySource variable … and that no longer exists…

maybe it can just be put back in… not sure…

… probably explains why the workers break when trying to add new readers to them, too…

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 >
React - TypeError: Cannot read property 'img' of undefined
The main issue is how you compute a random card, you are indexing out of the array. const randCard = cards[Math.floor(Math.random() ...
Read more >
How to Prevent the Error: Cannot Read Property '0' of Undefined
A guide on how to prevent the error "cannot Read Property '0' of Undefined", covering techniques such as try, catch, using const over...
Read more >
Uncaught TypeError: Cannot read property of undefined In
Uncaught TypeError : Cannot read property of undefined error occurs in Chrome when you read a property or call a method on an...
Read more >
Cannot read properties of undefined (reading 'id') - TrackJS
We'll often run into errors like “Cannot read properties of undefined ... TypeError is a subset of JavaScript Error that is thrown when...
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