Magento – slick slider error Uncaught TypeError: Cannot read property ‘add’ of null in magento2

magento2slickslider

I have applied slick slider in the phtml file but is giving error

Uncaught TypeError: Cannot read property 'add' of null in browser

here is my code

<script type="text/javascript">

    require(['jquery', 'slick'], function($){ 
    jQuery(document).ready(function ($) {
           jQuery('.slickslider').slick({
      dots: false,
      infinite: false,
      speed: 300,
      slidesToShow: 3.1,
      settings: "unslick",
      slidesToScroll: 1,
      responsive: [
        {
          breakpoint: 1024,
          settings: {
            slidesToShow: 3.1,
            slidesToScroll: 1,
            infinite: false,
            dots: false
          }
        },
         {
          breakpoint:767,
          settings: {
            slidesToShow: 3.2,
            slidesToScroll: 1,
             dots: false
          }
        },
        {
          breakpoint: 600,
          settings: {
            slidesToShow: 3.1,
            slidesToScroll: 1,
             dots: false
          }
        },
           {
          breakpoint: 320,
          settings: {
            slidesToShow: 2.1,
            slidesToScroll: 1,
             dots: false
          }
        },
        {
          breakpoint: 480,
          settings: {
            slidesToShow: 2.1,
            slidesToScroll: 1,
             dots: false
          }
        }
        // You can unslick at a given breakpoint now by adding:
        // settings: "unslick"
        // instead of a settings object
      ]
    });
});
});
createSlick();

//Now it will not throw error, even if called multiple times.
 $(window).on( 'resize', createSlick );

Best Answer

That's due to calling init twice This works without error:

$(".slickslider").not('.slick-initialized').slick()