Uncaught TypeError: $ is not a function

Hello there.

I’m quite new to Root and it seems I’m having trouble with jQuery, but I don’t know why.
Here the situation: I was developing a theme and everything seemed to work fine. Suddenly (I assure you, if I did something I can’t understand what I’ve done) the console is giving me this error, and I don’t know why.

Maybe a second pair of eye can help me figure out what is going on:
manifest.json

{
  "dependencies": {
    "main.js": {
      "files": [
        "scripts/main.js"
      ],
      "main": true
    },
    "main.css": {
      "files": [
        "styles/main.scss"
      ],
      "main": true
    },
    "editor-style.css": {
      "files": [
        "styles/editor-style.scss"
      ]
    },
    "carousel.js": {
      "files": [
        "scripts/carousel.js"
      ],
      "bower": [
        "fullpage.js",
        "slick-carousel"
      ]
    },
    "carousel.css": {
      "files": [
        "styles/carousel.scss"
      ],
      "bower": [
        "fullpage.js",
        "slick-carousel"
      ]
    },
    "jquery.js": {
      "bower": ["jquery"]
    },
    "modernizr.js": {
      "bower": ["modernizr"]
    }
  },
  "config": {
    "devUrl": "http://local.wordpress.dev/"
  }
}

carousel.js

(function($){
	"use strict";

	$(document).ready(function(){

	});
})(jQuery);

asset function

function assets() {
  wp_enqueue_style('mdl_icons', 'https://fonts.googleapis.com/icon?family=Material+Icons', false, null);
  wp_enqueue_style('sage_css', asset_path('styles/main.css'), false, null);

  if (is_single() && comments_open() && get_option('thread_comments')) {
    wp_enqueue_script('comment-reply');
  }

  wp_enqueue_script('modernizr', asset_path('scripts/modernizr.js'), [], null, true);
  wp_enqueue_script('sage_js', asset_path('scripts/main.js'), ['jquery'], null, true);
  if (is_front_page()) {
    wp_enqueue_script('frontpage_js', asset_path('scripts/carousel.js'), ['jquery'], null, true);
    // wp_enqueue_style('frontpage_css', asset_path('styles/carousel.css'));
  }
}

The Uncaught TypeError: $ is not a function is on main.js : 2…but I did nothing on main.js

Thank you for any help you can give me

Try this:

(function($){
	"use strict";

	jQuery(document).ready(function(){

	});
})(jQuery);

replacing the $ with jQuery resolved this issue for me in the past.

1 Like