Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

88
Visualizações
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 Respostas
Responde à pergunta

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 Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda