Since few days i try to fix issue with my mCustomScrollbar plugin and i got stuck.

First of all i i've got library with mCustomScrollbar.js and mousewheel.js in


and my script in

web/js .

I added mCustomScrollbar.js and mousewhell.js to requirejs-config with path and shims.

My script looks like:

function ($, mCustomScrollbar) {
    'use strict';
    return function (config, element) {
            theme: 'dark'

The problem is - when i open page (where my script is applying) sometimes console shows

Uncaught TypeError: $(...).mCustomScrollbar is not a function

and script doesn't work. Sometimes it works perfect. I don't know why it happens differently. When i open my page first time all looks good when i refresh - it depends, sometimes still works good (no errors, script applied) but sometimes doesn't work (with error above).

Can anyone tell me what wrong i do or why it happens differently?


1 Answer 1


I have used same jq plugin in my Magento 2 site. I have used "mCustomscrollbar.js" at Product Listing page. Here are the steps to use the js.

1) app/design/frontend/Vendor/Theme/Magento_Catalog/web/js/ : Upload "mCustomScrollbar.js" and "mousewheel.js" js file here. 2) app/design/frontend/Vendor/Theme/Magento_Catalog/templates/product/list.phtml add below code in this file.

<script type="text/javascript">
    require(['jquery', 'jquery/ui','Magento_Catalog/js/mousewheel','Magento_Catalog/js/mCustomScrollbar'], function($){
        $(document).ready(function($) {

You can add the options of mCustomscrollbar here as per your requirement. This code is working fine for me. Hope this will help you. :)

  • I did a modification with document.ready function and it stopped to throw an error on the specific js library. Unfortunately, it keeps throwing js errors on console and the site doesn't load correctly but now the errors are on the other scripts. That means the root cause is not the JS file and there is some misunderstanding with browser/cache js files against the server load order/responses. I upgraded the Magento to the latest version (2.3.3) with no luck solving the issue. Nov 25, 2019 at 13:39
  • I did the same changes which I have mentioned in my answer above, and working fine for me. Let me know your error to help you. Thank you. Nov 26, 2019 at 10:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.