Slick Carousel Uncaught TypeError: $(…).slick is not a function

前端 未结 15 1588
独厮守ぢ
独厮守ぢ 2020-12-10 00:18

Somehow I\'m unable to use slick carousel (http://kenwheeler.github.io/slick/) correctly.

I\'m getting the following error:

Uncaught TypeError: $(..         


        
15条回答
  •  一整个雨季
    2020-12-10 01:02

    I'm not 100% sure, but I believe the error was caused by some client-side JavaScript that was turning exports into an object. Some code in the Slick plugin (see below) calls the require function if exports is not undefined.

    Here's the portion of code I had to change in slick.js. You can see I am just commenting out the if statements, and, instead, I'm just calling factory(jQuery).

    ;(function(factory) {
    console.log('slick in factory', define, 'exports', exports, 'factory', factory);
    'use strict';
    // if (typeof define === 'function' && define.amd) {
    //     define(['jquery'], factory);
    // } else if (typeof exports !== 'undefined') {
    //     module.exports = factory(require('jquery'));
    // } else {
    //     factory(jQuery);
    // }
    factory(jQuery);
    }
    

提交回复
热议问题