slick: Webpack - $(...).slick is not a function
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
About this issue
- Original URL
- State: closed
- Created 8 years ago
- Comments: 17
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:
Thanks
or just
script-loader did the trick for me:
Hi. I found solution which works for me:
add to
js
file:add to
scss
file:Hello, after some investigation I’ve found out that by commenting the first block of code and leaving the else part, fixed the issue, as below:
I’ll keep on digging, but if any of you have an idea, it would be appreciated.
Thanks,
😃
@chbdetta I’m using
slick-carousel-browserify
script instead ofslick-carousel
When import changed to
import 'slick-carousel';
no import errors, but receive
updated in master
I have the same error here,
I install package with
npm
And withexpose-loader
to expose jquery towindow.$
andwindow.jQuery
. By debugging, I find out the slick has its own copy of jquerythe $ in slick is at version 3.2.1, and the global jquery I expose is 1.10.x, so when I use
$().slick
in my code.slick
is not found.And when using
yarn
to install the package, no error.