question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Webpack - $(...).slick is not a function

See original GitHub issue

Hello,

I’m trying to use webpack to bundle all my js files and libraries. So far it works well for other plugins but when calling and using slick, I’m getting a: Uncaught TypeError: $(…).slick is not a function

Main JS file codes:

global.jQuery = require('./vendor/jquery/dist/jquery');
window.$ = global.$ = global.jQuery;

//Add bootstrap & libraries
require('./vendor/bootstrap/dist/js/bootstrap');
require('./vendor/slick-carousel/slick/slick');

$(document).ready(function(){

  $(".slider").slick({
    infinite: false
  });
});

ps: “vendor” is the custom name given for “bower_components”

my webpack config:

var config = {
  watch: false,
  output: {
    filename: 'app.js'
  },
  plugins: [
    new webpack.optimize.DedupePlugin(),
    new webpack.optimize.OccurenceOrderPlugin(),
    new webpack.optimize.UglifyJsPlugin({
      sourceMap: true,
      mangle: {
        except: ['$super', '$', 'exports', 'require']
      },
      output: {
        comments: false
      }
    })
  ],
  devtool: 'source-map'
}

What is observed behaviour?

Slick carousel is not being executed.

More Details

  • Which browsers/versions does it happen on? Chrome 49 Firefox 44.0.2
  • Which jQuery/Slick version are you using? jQuery 2.2.3/Slick 1.5.9
  • Did this work before? Yes, before webpack integration

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:17

github_iconTop GitHub Comments

30reactions
umarmwcommented, May 2, 2016

Hello,

I’ve found the fix for the issue; it by declaring jquery as global in the webpack configuration:

http://stackoverflow.com/questions/28969861/managing-jquery-plugin-dependency-in-webpack

Point 2:

var webpack = require("webpack");

    ...

    plugins: [
        new webpack.ProvidePlugin({
            $: "jquery",
            jQuery: "jquery"
        })
    ]

Thanks

22reactions
noomzcommented, Oct 3, 2016

or just

import $ from 'jquery';

import 'slick-carousel';
import 'slick-carousel/slick/slick.css';
import 'slick-carousel/slick/slick-theme.css';
Read more comments on GitHub >

github_iconTop Results From Across the Web

Slick Carousel Uncaught TypeError: $(...).slick is not a function
I found out that that means that the code has been loaded before the DOM was loaded, which is correct (I think). Edit:...
Read more >
TypeError: $(...).slick is not a function in jQuery | bobbyhadz
To solve the "$(...).slick is not a function" jQuery error, make sure to load the jQuery library before loading the slick library. The...
Read more >
jquery 32 1 min js 2 uncaught typeerror slick is not a function
Uncaught TypeError: $().slick is not a function Usually means that you either forgot to include slick.js in the page or you included it...
Read more >
Uncaught TypeError: $().kendoGrid is not a function - Telerik
I am trying to use Kendo Grid in a view. In the main index.html I have reference for the required css and js...
Read more >
Uncaught TypeError | Is Not A Function | Solution - YouTube
Have you encountered an error like:- Uncaught TypeError- Some selector is not a function - jQuery is not a function - owlCarousel is...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found