Search code examples
javascriptrequirejslazy-loadingmagento2polyfills

Lazyload polyfill / Magneto 2 js error "loading-attribute-polyfill.js Uncaught ReferenceError: module is not defined"


I am trying to load this lazyload polyfill script into my Magneto 2 project.

The code works but there is a console error I am trying to fix and having no luck.

Chrome console: loading-attribute-polyfill.js Uncaught ReferenceError: module is not defined at loading-attribute-polyfill.js:263

Safari console: ReferenceError: Can't find variable: module

I have tried loading it in the head via xml, manually before end in a phtml template, and also through requirejs-config.js, all give the same error.

In case it matters I was loading it via requirejs like this:

var config = {
    deps: [
      "js/vendor/loading-attribute-polyfill"
    ],
    map: { ... } 
};

Has anyone implemented this script into magento 2 without this error? Is there a manual edit I can make to the script to workaround this?

Cheers!!

enter image description here


Solution

  • Which version of this polyfil are you trying to use? There are many versions https://github.com/mfranzke/loading-attribute-polyfill/tree/master/dist

    The UMD one looks to be RequireJS compatible, but will probably need changes in the config.