Skip to content

Top-Level Await

Top-level await allows you to use await at the top level of modules without wrapping it in an async function.

// In a module — no async function needed!
const response = await fetch('/api/config');
const config = await response.json();
console.log(config);
config.js
export const config = await fetch('/api/config').then(r => r.json());
// Module waits for this to resolve before its imports resolve
// main.js
import { config } from './config.js';
console.log(config); // Already loaded!
  • Only works in ES modules (not classic scripts)
  • Blocks the module’s execution (not the entire app)
  • Other modules importing this module will wait
  • Use with care — it delays module evaluation
  • await at the top level of modules
  • No async wrapper needed
  • Only in ES modules
  • Blocks the importing module chain