---
url: /docs/guide/usage/linter/rules/node/no-top-level-await.md
---

### What it does

Disallows the use of top-level `await`, including `for await...of` loops
and `await using` declarations that are not nested inside a function.

### Why is this bad?

Node.js v20.19 introduced `require(esm)`, but ES modules with top-level
`await` cannot be loaded with `require(esm)`. Avoiding top-level `await`
keeps a module loadable from both CommonJS `require()` and ESM
`import`.

### Examples

Examples of **incorrect** code for this rule:

```js
const foo = await import("foo");

for await (const e of asyncIterate()) {
  // ...
}
```

Examples of **correct** code for this rule:

```js
async function fn() {
  const foo = await import("foo");
}
```

## Configuration

This rule accepts a configuration object with the following properties:

### ignoreBin

type: `boolean`

default: `false`

If `true`, top-level `await` is allowed in files that start with a
hashbang (`#!`), which marks them as executable scripts rather than
importable modules.

## How to use

## Version

This rule was added in v1.75.0.

## References
