davidjerleke / embla-carousel

A lightweight carousel library with fluid motion and great swipe precision.
https://www.embla-carousel.com
MIT License
5.8k stars 175 forks source link

Console error: Uncaught TypeError: Cannot use 'in' operator to search for 'container' in null #295

Closed fabianwurk closed 2 years ago

fabianwurk commented 2 years ago

I have tried integrating as a module, but also the CDN method, but console is throwing the following error:

embla-carousel.umd.js:1 Uncaught TypeError: Cannot use 'in' operator to search for 'container' in null
    at b (embla-carousel.umd.js:1:11896)
    at T (embla-carousel.umd.js:1:12164)
    at A (embla-carousel.umd.js:1:14079)
    at (index):829:15

Any ideas why this may be happening?

davidjerleke commented 2 years ago

Hi @fabianwurk,

Thanks for your question. Probably because you’re passing null instead of an HTML element node to EmblaCarousel(). Passing null as the first argument to the EmblaCarousel() constructor isn't a valid:

const emblaNode = document.querySelector('.embla') // This is null in your case
const embla = EmblaCarousel(emblaNode) // So this throws an error because you need to pass a valid HTML element to it

Best, David

davidjerleke commented 2 years ago

@fabianwurk did you see my response?

fabianwurk commented 2 years ago

Thanks @davidjerleke - that makes sense.