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

244
Views
Top level await not working in ECMAScript

I am rather confused as I have read that top level await is supported in ESM but when I try it out in a html file it does not work?

Were I found that is says: Top-level await does not work with node 14.13.- "Top-level await only works with ESM modules"

Is top level await supported in ESM and if how can I use it.

document.getElementById('foo').innerHTML = 'hello1';
await pause(2000); // is this possible if so how
document.getElementById('foo').innerHTML = 'hello2';
about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Yes, it's supported in ESM - ES6 modules. It's not supported in plain script tags.

<script>
await Promise.resolve();
</script>

You need to specify that the script is a module for it to work.

<script type="module">
await Promise.resolve();
console.log('finished successfully');
</script>

(Also make sure that you're running this in a supported environment - older environments may not support top-level await)

about 4 years ago · Juan Pablo Isaza 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!