Uncaught TypeError: Cannot read properties of undefined (reading 'keyboard')

Viewed 41

what can be this problem? i go to carousel.js

_addEventListeners() {
    if (this._config.keyboard) {
      EventHandler.on(this._element, EVENT_KEYDOWN, event => this._keydown(event))
    }
}

1 Answers

I had it also. Upgraded and now it works with "bootstrap": "^5.2.1", But I am not sure what the problem was.

If you copy sample code from the bootstrap website check the element IDs carefully. I had to adjust mine.

If using vue make sure the DOM is ready:

  // import { Carousel } from 'bootstrap'
  // import * as bootstrap from 'bootstrap'
  import Carousel from 'bootstrap/js/dist/carousel'
  onMounted(() => {
    const carousel = new Carousel('#myCarousel')
  })

Also I changed the import statement according to this manual: https://getbootstrap.com/docs/5.2/customize/optimize/

I think this error is caused by the element parameter (no element) and not by the config parameter as the error message suggests

Related