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`.
Error [ERR_REQUIRE_ASYNC_MODULE]: Must use import to load ES Module: ... because it uses top-level await
// 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?
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.
Related Developer Error Solutions
Browse All 54 GuidesTS: Cannot find module or its type declarations
Resolve missing npm package types, misconfigured tsconfig path aliases, or missing declaration files.
Webpack: Module parse failed
Configure appropriate loaders for TypeScript, JSX, CSS modules, or modern JavaScript syntax.
Next.js Hydration Failed
Resolve Next.js React hydration mismatch errors caused by browser-only APIs (window, localStorage), timestamps, or invalid HTML nesting.
CORS 'Access-Control-Allow-Origin' Missing
Resolve browser cross-origin resource sharing errors by configuring backend HTTP headers and handling preflight OPTIONS requests.