Webpack / jquery.ns-autogrow Uncaught TypeError: Cannot read property 'fn' of undefined

718 views Asked by At

Hy there

I'm new to Webpack or JS-bundel in general. So this question might sound dumb. If so, I'm sorry..

I'm using webpack to bundle all JS files. So far I have this im main.js:

var jQuery  = require('jquery');
var autogrow = require('jquery.ns-autogrow');

(function($){

    $(function(){
        $('textarea').autogrow();
    });

})(jQuery);

But now I get Uncaught TypeError: Cannot read property 'fn' of undefined right at the beginning of the ns-autogrow plugin/module.

(function($, window) {
    return $.fn.autogrow = function(options) { ...

Is there something I made wrong requiring the dependencies?

1

There are 1 answers

5
Tony On

You have to include jquery dependency at the global scope of your app to use it this way :

(function($){

    $(function(){
        $('textarea').autogrow();
    });

})(jQuery);

To do it, you should use something like :

externals: {
    // require("jquery") is external and available
    //  on the global var jQuery
    "jquery": "jQuery"
}

you can see more details at this address

I hope it may help