Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

195
Views
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 answers
Answer question

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!