Search code examples
javascriptowl-carousel

jQuery Owl Carousel: Cannot read property ‘clone’ of undefined


I am not sure if this is an error but I am getting this in my console. It drives me crazy. I am running a WordPress site. My error is below.

Uncaught TypeError: Cannot read properties of undefined (reading 'clone')
    at e.run (owl.carousel.min.js?ver=1.3.2:1)
    at Object.i [as run] (jquery.min.js:2)
    at e.update (owl.carousel.min.js?ver=1.3.2:1)
    at e.refresh (owl.carousel.min.js?ver=1.3.2:1)
    at e.initialize (owl.carousel.min.js?ver=1.3.2:1)
    at new e (owl.carousel.min.js?ver=1.3.2:1)
    at HTMLDivElement.<anonymous> (owl.carousel.min.js?ver=1.3.2:1)

    at Function.each (jquery.min.js:2)
    at s.fn.init.each (jquery.min.js:2)
    at s.fn.init.a.fn.owlCarousel (owl.carousel.min.js?ver=1.3.2:1)

As a fix, I found that I must config loop: false for the slider that has only one item but I am not sure how I do that in my WordPress site.

This is the code that shows the error in owlCarousel.min.js

a.fn.owlCarousel = function(b) {
    return this.each(function() {
        a(this).data("owlCarousel") || a(this).data("owlCarousel", new e(this,b))
    })
}

This is the place that shows the error when I view the file path it navigates me to here. This is a WordPress website.

  var W = /^(Eval|Internal|Range|Reference|Syntax|Type|URI)Error$/;
    S.Deferred.exceptionHook = function(e, t) {
        C.console && C.console.warn && e && W.test(e.name) && C.console.warn("jQuery.Deferred exception: " + e.message, e.stack, t)
    }
    ,
    S.readyException = function(e) {
        C.setTimeout(function() {
            throw e
        })
    }
    ;

This says Jquery deferred exception


Solution

  • Try this :

    I found that setting the loop option to false resolved it for me.

        jQuery('.owl-carousel2').owlCarousel({
            loop:false,
            margin:10,
            nav:true,
            mouseDrag:false,
            responsive:{
                0:{
                    items:1
                },
                600:{
                    items:3
                },
                1000:{
                    items:3
                }
            }
        })
    
      });
    

    Reference : Cloned items in owl carousel