$ is not a function

Hello,
I’m starting to build a theme with Sage and I’m having some problems loading script files.
I understood that I have to use the manifest.json file and so I did:

  "dependencies": {
    "main.js": {
      "files": [
        "scripts/script.js",
        "scripts/main.js"
      ],
      "main": true
    },

I’m trying to add a plugin I wrote, which uses the factory pattern. Its structure is basically this:

;(function(factory){

    if (typeof define === 'function' && define.amd) {
        define(['jquery'], factory);
    } else if (typeof exports !== 'undefined') {
        module.exports = factory(require('jquery'));
    } else {
        factory(jQuery);
    }

})(function($){

     var Plugin = (function(element, settings){

        return _Plugin;

    })();


});

var args = {
 ...
};

$('.carousel').Plugin(args);

I cut away most of the code, it’s just to give you an idea. Anyway, when I load the page I get the error “$ is not a function”. What am I doing wrong?
I tried with a simple script, like this:

(function($) {
    console.log($);
})(jQuery);

and it works. How can I do to make the plugin to work?

Thanks!

WordPress enqueues jQuery in no-conflict mode. This link might be helpful.

1 Like