Javascript file attached via Drupal behaviours does not work occasionally
You are firing your event on document context, which happens only once (basically same as old school $(document).ready()). But a major point Drupal behaviors is that they are fired every time when somehing is added to the DOM, even when added with Ajax. (core's  BigPipe might add blocks with Ajax, this module is enabled by default)
So instead of the one-shot
  Drupal.behaviors.basics = {
    attach: function (context, settings) {
      if (context !== document) {
        return;
      }
      ...do stuff

target the specific DOM nodes, e.g. if your carousel has a container
&lt;div class=&quot;my_fancy_carousel&quot;&gt;...&lt;/div&gt;
attach the behavior to its class:
  Drupal.behaviors.my_fancy_carousel  {
    attach: function (context, settings) {
      $('.my_fancy_carousel', context).once('init_my_fancy_carousel').each( function() {
        ...do stuff...

Also notice the .once('my_unique_identifier') part which makes sure your functions don't trigger repeatly on the same DOM node