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

87
Vistas
Webpack import behaviour

I am currently moving over to using webpack, and have added this piece of code before the initialization of my app.

delete window.IntersectionObserver;

if (!('IntersectionObserver' in window)) {
    console.log(`Load observer`);
    import('/node_modules/intersection-observer/intersection-observer.js');
    console.log(`Loaded`);
}

console.log(`Start`);

I delete the IntersectionObserver for testing purposes only.

But when I run the code I get the logs like Load observer -> Loaded -> Start

But as far as I know, import returns a promise, which means is should be async, or is this some different behaviour I am not familiar with?

I was expecting Load observer -> Start -> Loaded.

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

0

If you want to wait for the promise - you should put the second console.log inside a then() clause like this

delete window.IntersectionObserver;

if (!('IntersectionObserver' in window)) {
    console.log(`Load observer`);
    import('/node_modules/intersection-observer/intersection-observer.js').then(module => console.log(`Loaded`));
}

console.log(`Start`);

or use async/await like this

(async () =>
{
delete window.IntersectionObserver;

if (!('IntersectionObserver' in window)) {
    console.log(`Load observer`);
    await import('/node_modules/intersection-observer/intersection-observer.js');
    console.log(`Loaded`);
}

console.log(`Start`);
})();
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