How to Fix ERR_REQUIRE_ASYNC_MODULE in Node.js
When a CommonJS file (one that uses require) calls require() on an ES module package and stops with Error [ERR_REQUIRE_ASYNC_MODULE], it means that some module in the loaded module or in the modules it imports uses top-level await (an await written outside any function). Changing require() to import(), or making your own file an ES module, makes the error go away.
In Node.js 22 and 24, require() can load ES modules, but it cannot load ones that contain top-level await. I created a small package with top-level await, got the error on Node.js 22 and 24, and checked the full error message, how to find where the await is, and that the error disappears after the fix.
I tested on Ubuntu 24.04 with Node.js 22.23.5 and 24.22.3. I did not test Node.js 20, Windows or macOS, running TypeScript after conversion, or the same error inside tools such as Jest or webpack.
The file that triggers the error
I created an ES module package named neko-config by hand in node_modules. Its package.json has "type": "module", and the entry file index.js only imports settings.js.
import { settings } from './settings.js';
export function getName() {
return settings.name;
}
The top-level await is in settings.js. I print a line on the first line so I can tell when it is loaded.
console.log('settings.js: 読み込み開始');
const loadSettings = async () => ({ name: 'neko' });
export const settings = await loadSettings();
The CommonJS app's index.js loads this (the app's package.json has no type field).
const { getName } = require('neko-config');
console.log(getName());
The full error message
I ran node index.js with Node.js 24.22.3. It stopped with the following output (exit code 1; paths are placeholders I substituted for the example).
$ node index.js
node:internal/modules/esm/module_job:313
throw new ERR_REQUIRE_ASYNC_MODULE(filename, parent, locations);
^
Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead. To see where the top-level await comes from, use --experimental-print-required-tla.
Required module: /path/to/app/node_modules/neko-config/index.js
Require stack:
- /path/to/app/index.js
at ModuleJobSync.throwIfAsyncGraph (node:internal/modules/esm/module_job:313:11)
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:662:10)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:347:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1747:24)
at Module._compile (node:internal/modules/cjs/loader:1911:5)
at Object..js (node:internal/modules/cjs/loader:2060:10)
at Module.load (node:internal/modules/cjs/loader:1651:32)
at Module._load (node:internal/modules/cjs/loader:1443:12)
at wrapModuleLoad (node:internal/modules/cjs/loader:261:19)
at Module.require (node:internal/modules/cjs/loader:1674:12) {
code: 'ERR_REQUIRE_ASYNC_MODULE'
}
Node.js v24.22.3
The Error [ERR_REQUIRE_ASYNC_MODULE] line means: "require() cannot be used on an ESM graph (the connected set of ES modules) that contains top-level await. Use import() instead. To see where the top-level await is, use –experimental-print-required-tla." Required module: is the module that was being loaded, and the line under Require stack: is the file that called require().
Note that Required module: points to index.js, which has no top-level await. The name of settings.js, where the await is written, does not appear anywhere in the message. The official documentation on loading ES modules with require() also says that this error occurs when a module imports another module that has top-level await, not only when the loaded module itself has it.
On Node.js 22.23.5, the Error [ERR_REQUIRE_ASYNC_MODULE] line had the same text. The two lines below it were formatted differently: From followed by the file that called require(), and Requiring followed by the module being loaded (the at … stack lines are omitted).
Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead. To see where the top-level await comes from, use --experimental-print-required-tla.
From /path/to/app/index.js
Requiring /path/to/app/node_modules/neko-config/index.js
On both versions, the load message printed by the first line of settings.js was not printed.
Finding the top-level await
As the message suggests, running with --experimental-print-required-tla shows where the await is. On Node.js 24.22.3 it printed the following (the at … stack lines and everything after them are omitted; paths are placeholders).
$ node --experimental-print-required-tla index.js
/path/to/app/node_modules/neko-config/settings.js:5
export const settings = await loadSettings();
^
Error [ERR_REQUIRE_ASYNC_MODULE]: require() cannot be used on an ESM graph with top-level await. Use import() instead.
Required module: /path/to/app/node_modules/neko-config/index.js
Require stack:
- /path/to/app/index.js
The first line points to line 5 of settings.js, and the ^ marks the position of await. This tells you which file to fix.
On Node.js 22.23.5 the output was different. The load message from settings.js was printed first, followed by the location of the await (the rest of the error is omitted).
$ node --experimental-print-required-tla index.js
settings.js: 読み込み開始
Error: unexpected top-level await at file:///path/to/app/node_modules/neko-config/settings.js:5
export const settings = await loadSettings();
^
On Node.js 22, the flag finds the location by actually running the module code. The Node.js 22 official documentation says it "evaluates the module to find the top-level await." The Node.js 24 official documentation states in its changelog that from 24.20.0 it reports the location "without evaluating the module."
On Node.js 22, when you use this flag, the code in the module before its await actually runs. If the module writes files or makes network requests, keep that in mind before you use it.
The fixes, and confirming the error goes away
Each of the three fixes below printed the settings.js load message and "neko" and exited with code 0 on both Node.js 22.23.5 and 24.22.3.
Keep CommonJS and load with import()
This is the approach the error message suggests. import() returns a Promise, so you receive the result with await inside an async function.
(async () => {
const { getName } = await import('neko-config');
console.log(getName());
})();
After I replaced the contents of index.js with this and ran node index.js again, the error no longer appeared (output from Node.js 24.22.3).
$ node index.js
settings.js: 読み込み開始
neko
You do not need to change package.json or any other file. However, code that uses getName must run after the await.
Make your own file an ES module
Rename the file to .mjs and load the package with import. ES modules can load each other even when there is top-level await.
import { getName } from 'neko-config';
console.log(getName());
node index.mjs printed "neko". If you want the whole project to be ES modules, you can keep the .js extension and add "type": "module" to package.json (official documentation on the "type" field). In that case, you also need to change the require calls in your other files to import.
Remove the top-level await in the module being loaded
If you wrote the module that has top-level await yourself, you can remove the await and export a Promise instead. I made a version of neko-config fixed this way and named it neko-config-sync. In settings.js I removed the await and exported the Promise.
console.log('settings.js: 読み込み開始');
const loadSettings = async () => ({ name: 'neko' });
export const settingsPromise = loadSettings();
In index.js, getName becomes an async function that waits for that Promise.
import { settingsPromise } from './settings.js';
export async function getName() {
const settings = await settingsPromise;
return settings.name;
}
With this change, the app could still load the package with require(). getName() returns a Promise, so you receive the value with then.
const { getName } = require('neko-config-sync');
getName().then((name) => console.log(name));
With this approach, the code that uses the package also has to handle a Promise. For a package installed from npm, do not edit its contents; instead, load it with the import() approach above or make your own file an ES module.
To find which file's await causes the problem, check the output of --experimental-print-required-tla, not the Required module: line in the error. Required module: shows the module you loaded directly with require(), which is not always the file that contains the await.





