Library: Unable to load module via requirejs or dojo loader

Created on 20 Aug 2020  路  6Comments  路  Source: zxing-js/library

Describe the bug
I want to use @zxing/library in a project that loads dependencies asynchronously using a call to require(). We actually depend on the dojo loader, but I have also tried requirejs. In both cases, the umd/index.min.js file is loaded, but the variable that is expected to contain ZXing is undefined.

To Reproduce
Steps to reproduce the behavior:

  1. npm install @zxing/library (or yarn or whatever)
  2. Create a new html page.
  3. Attempt to load ZXing via require, something like this:
    (this is the dojo configuration syntax)
<script type="text/javascript">
    require({
        packages: [
            {
                name: "@zxing/library",
                location: "./node_modules/@zxing/library",
                main: "umd/index.min"
            }
        ]
    });
    require(["@zxing/library"], function(ZXing) {
        console.log(ZXing);
    });
</script>

Expected behavior
I expect the console to log an object of the ZXing module. Instead I get undefined.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: Windows 10
  • Browser Firefox
  • Version 79.0

Additional context
A colleague suggested editing the umd/index.min.js file and removing the "ZXing" parameter from the call to define(). This allowed it to load for me. This would suggest that the use of a module name is complicating things.

bug no-issue-activity

Most helpful comment

Have you tryied v0.18.1 out? I completely changed the build system used for the UMD bundle. Maybe this will help out. I'd love some help on testing it anyway, it seems to work throught HTML script tags tho.

All 6 comments

Stale issue message

This is still relevant for me. We're currently using a gross hack in our release build to remove the offending "ZXing" parameter. I'd love to be able to take that out.

Have you tryied v0.18.1 out? I completely changed the build system used for the UMD bundle. Maybe this will help out. I'd love some help on testing it anyway, it seems to work throught HTML script tags tho.

We're currently using 0.17.1. I'll try 0.18.1 and let you know how it goes.

There's an even newer release, v0.18.2. I'll try to setup an AMD load test in future versions as it is a very important thing that fails sometimes.

We've updated to 0.18.2 and it now works without the hack. Nice!

We'll keep watching the updates with interest as we've observed inconsistent results with certain barcodes and I see some recent changes in your history to address that.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sabasayer picture sabasayer  路  3Comments

lenny76 picture lenny76  路  10Comments

helloo0-0oword picture helloo0-0oword  路  8Comments

majestic84 picture majestic84  路  8Comments

arthurmmedeiros picture arthurmmedeiros  路  3Comments