Skip to main content
TypeScript & Node.js · Developer Error Resolution Lab

Fix Node.js Error [ERR_REQUIRE_ASYNC_MODULE]: Cannot require() ES Module with Top-Level Await

Understand and fix `ERR_REQUIRE_ASYNC_MODULE` in Node.js 20.17+ and 22+ when CommonJS `require()` loads an ESM package containing top-level `await`.

Triggered Error Message:

Error [ERR_REQUIRE_ASYNC_MODULE]: Must use import to load ES Module: ... because it uses top-level await

Customize Solution for Your Environment
// Replace synchronous require("my-esm-pkg") with dynamic import():
const mod = await import("my-esm-pkg");

Root Cause & Mechanism Analysis

Why does this error occur?

Node.js 22+ supports `require(esm)` natively for synchronous ES modules, but synchronous `require()` cannot pause execution for an ES module that executes top-level `await` at evaluation time.

Frequently Asked Questions

Does Node.js 22 allow `require()` of regular ES modules without top-level await?
Yes! Node.js 22 enables `require(esm)` by default for any ES module graph that does not contain top-level `await`.
DEVSECOPS & CI/CD PARTNER2 Slots Open

Need Zero-Knowledge .env Secret Sync Across Your Engineering Team?

Explore Castov Env Vault for client-side AES-256-GCM encrypted environment sharing, or sponsor this engineering hub.

Browse All 54 Guides