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

191
Visualizações
Dynamic importing WASM. Order of execution issue

I'm trying to load a WASM library from another node js application (Both using webpack). On the WASM library, I have following code to export the functionality.

export default import("./pkg")
    .then(s => {
        let result = s.initialize_sync();
        console.log("result = ", result);
        return s;
    }).catch(error => {
        console.error(error);
        throw error;
    });

And on the application, I have the following.

let s = await import("s-wasm");
console.log("2 s = ", s);
      

I'm getting the following log lines when running the application.

2 s =  { default: {} }
result =  initialized

What I am expecting:

result =  initialized
2 s =  { default: {} }

I want the 2 s = line to be printed after WASM is loaded. but it is called before the WASM is loaded. How do I achieve this ? What am I doing wrong here ?

about 4 years ago · Santiago Gelvez
1 Respostas
Responde à pergunta

0

I would suggest you either write your module as

export * from "./pkg";
import { initialize_sync } from "./pkg";
console.log("result = ", initialize_sync());

or (if you really have to) with top-level await:

const s = await import("./pkg")
console.log("result = ", s.initialize_sync());
export default s;

so that you are not default-exporting a promise for s.

If you don't do that, your application code would need to be

let s = await (await import("s-wasm")).default;
console.log("2 s = ", s);
about 4 years ago · Santiago Gelvez 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