Magento 2 – Require Js Not a Function Error

magento2requirejsrequirejs-config.js

Firstly, yes I'm in developer mode Рand yes i've got the cach̩ turned off and flushing it ( i've also deleted pub/static a fair few times ).

My issue:

I have an extension which adds a page to the admin area of the site on this page Im using require js to call in plugins to do things. Here is my requirejs file:

var config = {
  map: {
    '*': {
        nestable:  'Vender_Default/js/jquery.nestable.min'
    }
  }
};

Which is inside of the following file:

vender/default/view/adminhtml/web/requirejs-config.js

and then in the page I'm doing the following:

require([
        'jquery',
        'nestable'
    ], function($, nestable) {
        $('#nestable').nestable({
                    group: 1,
                    maxDepth: 15
                }).on('change', updateOutput);
        });

Which i thought was correct, however i get the following errors:

Cannot read property 'fn' of undefined at jquery.nestable.min.js:1

and

TypeError: $(…).nestable is not a function

Which clearly its not now, because of the first error. Does anyone have any idea why I am getting this issue? I can't seem to get my head around why its not working. And most other questions on here don't seem to be the same issue.

** Have changed jQuery to $ and still receiving the error.

Thanks

Best Answer

You need to do as below, need to change jQuery to $ as argument,

require([
    'jquery',
    'nestable'
], function($, nestable) {
        $('#nestable').nestable({
            group: 1,
            maxDepth: 15
        }).on('change', updateOutput);
});