Mart Hagedoorn
Mart Hagedoorn

Reputation: 90

jQuery plugin gives "jQuery is not defined"

I am trying to build my own jQuery plugin. Ik looks as follows:

(function ( $ ) {

    $.fn.greenify = function() {
        this.css( "color", "green" );
        return this;
    };

}(jQuery));

However, when trying to run this plugin, the error:

jQuery is not defined

My app.js looks as the following:

import $ from 'jquery';
global.$ = global.jQuery = $;
import './greenify';

Can anybody help on why this is happening?

Edit

The issue was that it couldn't find jQuery. Wat fixed the issue was instead of

}(jQuery));

to type

}(global.jQuery));

And instead of import './greenify'; do:

require('./greenify');

Upvotes: 1

Views: 295

Answers (1)

Renzo Calla
Renzo Calla

Reputation: 7696

This is happening because you are importing $ variable try to changing to

(function ( $ ) {

    $.fn.greenify = function() {
        this.css( "color", "green" );
        return this;
    };

}($));

Upvotes: 1

Related Questions