Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

221
Vistas
javascript error in the console that prevents the rest of the javascript from working

I'm doing a project for my courses on symfony, I use webpack and the "slidejs" library to make carousels. Everything works fine on the page where I use splide but on the other pages where it's not used I get an error message in the console and all the rest of my javascript doesn't work anymore

Error: https://i.stack.imgur.com/x21fr.png

I'm importing the splide.js file into my app.js, my splide configuration looks like this

// Splide

// Last news
import Splide from '@splidejs/splide';
let splideEvents = new Splide( '#splideEvents', {
    classes: {
        arrow : 'splide__arrow bg-primary',
    },
    type: 'splide',
    perPage: 4,
    perMove: 1,
    gap: '10px',
    pagination: false,
    breakpoints: {
        992: {
            perPage: 2
        },
        500: {
            perPage: 1,
            gap: 0
        }
    }
} );
splideEvents.mount();


let splideNews = new Splide( '#splideNews', {
    classes: {
        arrow : 'splide__arrow bg-primary',
    },
    type: 'splide',
    perPage: 4,
    perMove: 1,
    gap: '10px',
    pagination: false,
    breakpoints: {
        992: {
            perPage: 2
        },
        500: {
            perPage: 1,
            gap: 0
        }
    }
} );
splideNews.mount();

let splideReleases = new Splide('#splideReleases', {
    classes: {
        arrow : 'splide__arrow bg-primary',
    },
    type: 'splide',
    perPage: 4,
    perMove: 1,
    gap: '10px',
    pagination: false,
    breakpoints: {
        992: {
            perPage: 2
        },
        500: {
            perPage: 1,
            gap: 0
        }
    }
})
splideReleases.mount();

Any ideas how to resolve this?

about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

You need to check if your elements are present in the dom or not :

if(document.querySelector('#splideEvents')) {
    let splideEvents = new Splide( '#splideEvents', {
        classes: {
            arrow : 'splide__arrow bg-primary',
        },
        type: 'splide',
        perPage: 4,
        perMove: 1,
        gap: '10px',
        pagination: false,
        breakpoints: {
            992: {
                perPage: 2
            },
            500: {
                perPage: 1,
                gap: 0
            }
        }
    } );

}

if they are not you don't do anything because there is no slide in the page

about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda