skip to Main Content

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

2

Answers


  1. Chosen as BEST ANSWER

    @DamianDziaduch after replying to your comment I tried using the UMD version again via requireconfig.js 'deps' and it does work, console error gone, must have been caching or something when I tried before 🤷‍♀️ thanks for the tip! Now I know to use UMD javascript where possible in magento2/requirejs (I did not come across this info when Googling!) 👍😎👍


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search