Requirejs lib not a function

95 Views Asked by At

I'm trying to use willmcpo/body-scroll-lock on my magento 2 site, but I don't think I'm including the body-scroll-lock lib correctly as it says:

TypeError: disableBodyScroll is not a function

Does anyone know what is the correct way to do this please?

main.js

require([
  'jquery',
  'bodyScrollLock'
], function ($) {
  $(function(){    
    const 
      // bodyScrollLock = require('body-scroll-lock');
      disableBodyScroll = bodyScrollLock.disableBodyScroll,
      enableBodyScroll = bodyScrollLock.enableBodyScroll,
      scrollMobileMenu = document.querySelector('.mobile-menu');    

    disableBodyScroll(scrollMobileMenu);
  });
});

requirejs-config.js

var config = {
  map: {
        "*": {
          'bodyScrollLock': 'js/libs/bodyScrollLock'
        }
    },
  deps: [
    'bodyScrollLock'
  ]
};
1

There are 1 best solutions below

0
On

Figured it out I just needed to include bodyScrollLock here

], function ($, bodyScrollLock) {