To fix ERR_REQUIRE_ESM, first check your Node.js version: since Node.js 22.12.0 and 20.19.0, require() can load ES modules without any flag, so on Node 22.12+, 24 or 26 the error usually disappears after upgrading. If you still see it on a current Node, something is loading your code with an older module system (Jest, an old TypeScript or bundler setup, or the --no-require-module flag), or the package you require uses top-level await, which produces the related ERR_REQUIRE_ASYNC_MODULE instead. The fallback that works everywhere is a dynamic import().
Every error message in this guide was reproduced on Node.js 24.15.0 with small local packages. I shortened the absolute paths to /home/dev/app for readability; everything else is verbatim output.
What ERR_REQUIRE_ESM means
Node.js has two module systems. CommonJS (CJS) uses require() and module.exports and loads synchronously. ECMAScript modules (ESM) use import and export and were designed to load asynchronously. For years, require() refused to load ESM at all, so when a dependency went "ESM-only" (as many popular packages did) any CommonJS project that required it crashed on startup:
Error [ERR_REQUIRE_ESM]: require() of ES Module /home/dev/app/node_modules/esm-only/index.js from /home/dev/app/a.js not supported.
Instead change the require of index.js in /home/dev/app/a.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (/home/dev/app/a.js:1:13) {
code: 'ERR_REQUIRE_ESM'
}
Node.js v24.15.0
A file is treated as ESM when it has a .mjs extension, or a .js extension with "type": "module" in the nearest package.json, or (since require(esm) support) a .js file with no type field that contains ESM syntax. Those rules are from the Node.js modules documentation.
I produced that output on Node 24 by deliberately disabling the modern behavior with --no-require-module. Without the flag, the same require() call works, which is the most important fact in this article.
Which Node.js versions support require(esm)
From the version history in the Node.js modules docs:
| Node.js version | require() of ESM |
|---|---|
| 20.17 / 22.0 | Added behind --experimental-require-module |
| 22.12.0, 23.0.0 | Enabled by default (no flag), with an experimental warning |
| 20.19.0 | Enabled by default, no warning |
| 22.13.0, 23.5.0 | Experimental warning removed |
| 24.15.0, 25.4.0 | Marked stable; --require-module / --no-require-module flags added |
| 26.x (current LTS) | Stable |
Node 24's changelog shows the stability change landing in 24.15.0 (April 15, 2026). Also note that Node 20 reached end of life on April 30, 2026, per the Node.js release schedule, so the practical baseline today is Node 22, 24 or 26. If you are planning a runtime bump anyway, our Node.js 26 LTS upgrade guide covers the other changes.
You can check support at runtime:
node -p "process.features.require_module"
# true
Fix 1: Upgrade Node.js and require the module directly
On Node 22.12+ the CommonJS code that used to crash just works. Here is the same a.js from above, run on Node 24 without flags:
// a.js (CommonJS project, package.json has "type": "commonjs")
const mod = require('esm-only');
console.log(mod);
console.log(mod.default('world'));
[Module: null prototype] {
__esModule: true,
default: [Function: greet],
version: '1.0.0'
}
hello world
The result is the module namespace object, the same thing import() gives you. Two details trip people up:
- The default export is on
.default.require('esm-only')is not the function;require('esm-only').defaultis. Destructure it:const { default: greet, version } = require('esm-only'). - Node adds
__esModule: truewhen the module has a default export, so code compiled by TypeScript or Babel (which checks that flag) picks up the default export correctly.
If you upgraded and still get ERR_REQUIRE_ESM, check three things: node -v in the environment that actually runs the code (CI images and Docker base images are often older than your laptop), whether NODE_OPTIONS contains --no-require-module, and whether a tool is replacing Node's require with its own (Jest, older ts-node, some bundler runtimes).
Fix 2: ERR_REQUIRE_ASYNC_MODULE when the module uses top-level await
require() is synchronous, so it cannot load a module graph that contains top-level await. In that case modern Node throws a different error:
// b.js
const cfg = require('tla-pkg'); // tla-pkg/index.js: const config = await Promise.resolve({...})
console.log(cfg);
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 /home/dev/app/b.js
Requiring /home/dev/app/node_modules/tla-pkg/index.js
at ModuleJobSync.runSync (node:internal/modules/esm/module_job:537:13)
at ModuleLoader.importSyncForRequire (node:internal/modules/esm/loader:366:47)
at loadESMFromCJS (node:internal/modules/cjs/loader:1649:24)
code: 'ERR_REQUIRE_ASYNC_MODULE'
}
The top-level await may be deep in the dependency graph, not in the package you required. The flag in the message finds it:
node --experimental-print-required-tla b.js
Error: unexpected top-level await at file:///home/dev/app/node_modules/tla-pkg/index.js:1
const config = await Promise.resolve({ ready: true });
^
You cannot fix this by upgrading Node. Your options are to load that module with import() (Fix 4), pin an older version of the dependency that did not use top-level await, or ask the maintainer to move the await into an exported async function.
Fix 3: ERR_PACKAGE_PATH_NOT_EXPORTED with "import"-only exports
Some packages declare their entry point only under the import condition in package.json exports. require() resolves with the require condition, finds nothing, and fails before it even reaches the ESM loader:
{ "name": "import-only", "type": "module", "exports": { ".": { "import": "./index.js" } } }
Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: No "exports" main defined in /home/dev/app/node_modules/import-only/package.json
at exportsNotFound (node:internal/modules/esm/resolve:310:10)
at packageExportsResolve (node:internal/modules/esm/resolve:601:13)
at resolveExports (node:internal/modules/cjs/loader:685:36)
As a consumer, use import(). If you maintain the package, see the author section below: the module-sync condition or a default condition fixes this for every consumer.
Fix 4: Use dynamic import() from CommonJS
Dynamic import() works in every CommonJS file on every supported Node version, handles top-level await, and respects import conditions. The trade-off is that it is asynchronous, so the calling code must be too:
// d.js (CommonJS)
let cfgPromise;
function getConfig() {
cfgPromise ??= import('tla-pkg').then((m) => m.default);
return cfgPromise;
}
async function main() {
const cfg = await getConfig();
console.log(cfg); // { ready: true }
}
main();
Caching the promise means the module is loaded once even if getConfig() is called from many places. For a server, load the module during startup before you start listening, so request handlers never wait on it.
Fix 5: TypeScript module settings that cause ERR_REQUIRE_ESM
TypeScript is the most common hidden cause, because it decides whether your import statements become require() calls. I tested each setting with TypeScript 7.0.2 (the Go-based compiler; see our TypeScript 7 migration guide) in a project with "type": "commonjs", importing an ESM-only package:
// src/index.ts
import greet, { version } from "esm-only";
console.log(greet("world"), version);
module setting |
Compile result | Runtime on Node 24 |
|---|---|---|
node16 |
error TS1479 | Emitted code runs (Node supports it, TypeScript just refuses) |
node18 |
error TS1479 | Same |
node20 |
Compiles | hello world 1.0.0 |
nodenext |
Compiles | hello world 1.0.0 |
commonjs |
Compiles | hello world 1.0.0 |
The TS1479 error under node16 and node18 is the compile-time version of ERR_REQUIRE_ESM:
src/index.ts(1,32): error TS1479: The current file is a CommonJS module whose imports will produce 'require' calls; however, the referenced file is an ECMAScript module and cannot be imported with 'require'. Consider writing a dynamic 'import("esm-only")' call instead.
Those modes model Node versions that could not require() ESM. Switch to "module": "node20" or "nodenext", which model current Node behavior. Also, TypeScript 7 removed the old moduleResolution: "node" (node10) setting entirely, so a legacy config now fails with error TS5108: Option 'moduleResolution=node10' has been removed.
The dynamic import trap with module: commonjs
This one is subtle. With "module": "commonjs", TypeScript rewrites dynamic import() into require(). I compiled this:
export async function loadConfig() {
const { default: cfg } = await import("tla-pkg");
return cfg;
}
and got this output, which defeats the whole point of using import():
const { default: cfg } = await Promise.resolve().then(() => __importStar(require("tla-pkg")));
At runtime that throws ERR_REQUIRE_ASYNC_MODULE for a top-level-await package, or ERR_REQUIRE_ESM on old Node. With "module": "nodenext" (or node20), TypeScript preserves the real import("tla-pkg"), and the same code printed { ready: true }. A working tsconfig for a CommonJS Node project:
{
"compilerOptions": {
"module": "nodenext",
"target": "es2022",
"outDir": "dist",
"rootDir": "src",
"strict": true
}
}
Fix 6: ERR_REQUIRE_ESM in Jest
Jest does not use Node's require; it has its own module registry. With Jest 30.5.2 on Node 24.15.0, requiring the same ESM-only package from a CommonJS test failed with Jest's version of the error:
Must use import to load ES Module: /home/dev/app/node_modules/esm-only/index.js
The file contains ESM syntax (import/export) that could not be executed as CommonJS. Either:
- Configure a transform (e.g. babel-jest) that compiles this file to CommonJS (see https://jestjs.io/docs/code-transformation)
- If the file is in "node_modules", allow it to be transformed by adjusting "transformIgnorePatterns" (see https://jestjs.io/docs/configuration#transformignorepatterns-arraystring)
- Use Node v24.9+ where Jest supports require(esm) natively (see https://jestjs.io/docs/ecmascript-modules#require-of-esm)
Jest's ECMAScript modules docs say Jest supports require() of ESM on Node 24.9 and later. In my test that support only kicked in with Node's VM modules flag enabled, which Jest's ESM support has always required:
NODE_OPTIONS="--experimental-vm-modules" npx jest
# Test Suites: 1 passed, 1 total
You will see an ExperimentalWarning: VM Modules is an experimental feature line; it is harmless. If you cannot use the flag, the older fix still works: let Babel or ts-jest transform the offending package by excluding it from transformIgnorePatterns:
// jest.config.js
module.exports = {
transformIgnorePatterns: ["/node_modules/(?!(esm-only|another-esm-pkg)/)"],
};
Also note from the Jest docs that jest.mock() does not apply to ESM files you require(); use jest.unstable_mockModule() for those. Many teams take this moment to move to Vitest, which is ESM-native; if you also use Vite, our Vite 8 migration guide covers that toolchain.
Fix 7: ts-node and running TypeScript directly
ts-node in its default CommonJS mode compiles imports to require() and hooks Node's loader, which is a frequent source of ERR_REQUIRE_ESM in older projects. On current Node you usually do not need it. Node runs .ts files directly through type stripping, enabled by default since 22.18.0 and 23.6.0 and stable since 24.12.0 and 25.2.0, per the Node.js TypeScript docs:
node src/index.ts
Type stripping does not read tsconfig.json and does not support every TypeScript feature (for example, enums need a transform). For full TypeScript semantics, the Node docs suggest a third-party runner such as tsx, which handles ESM and CJS interop without ts-node's configuration.
For package authors: make require() work for everyone
If you publish an ESM-only package, three small changes stop your users from hitting these errors:
- Avoid top-level
awaitin anything reachable from your main entry. Export an asyncinit()instead. - Expose a
module-syncordefaultcondition, not justimport. Node documentsmodule-syncas matching forimport,import()andrequire(), for ESM without top-levelawait:
{
"type": "module",
"exports": {
".": {
"module-sync": "./index.js",
"default": "./index.js"
}
}
}
- Consider a
"module.exports"export if CommonJS users expect the default export directly. Node's docs showexport { Point as 'module.exports' }, which makesrequire('pkg')returnPointinstead of the namespace. The catch: named exports are then lost to CommonJS consumers unless you attach them as properties of the default export.
Troubleshooting checklist
- Run
node -vwhere the code actually runs. Below 22.12 (or 20.19 on the 20 line), upgrade. - Check
NODE_OPTIONSand npm scripts for--no-require-module. - Seeing
ERR_REQUIRE_ASYNC_MODULE? Find the top-levelawaitwith--experimental-print-required-tla, then useimport(). - Seeing
ERR_PACKAGE_PATH_NOT_EXPORTED? The package only exports forimport; useimport(). - TypeScript project? Set
"module": "nodenext"or"node20", and check the compiled output forrequire(where you wroteimport(. - Jest? Run with
--experimental-vm-modulesor transform the package. - Still stuck? Diff the package's
package.jsonexportsbefore and after the version bump that broke you, using a code difference checker.
Frequently Asked Questions
How do I fix "require() of ES Module not supported"?
Upgrade to Node.js 22.12 or later (or 20.19+), where require() loads ES modules by default. If you must stay on an older Node, replace require('pkg') with await import('pkg') inside an async function.
Why do I still get ERR_REQUIRE_ESM on Node 22 or 24?
Something other than Node's own require is loading the file. Common causes are Jest's module registry, TypeScript or a bundler rewriting import() into require(), ts-node hooks, or --no-require-module set in NODE_OPTIONS. Check the stack trace to see which tool threw.
What is ERR_REQUIRE_ASYNC_MODULE?
It is thrown when you require() an ES module whose graph contains top-level await. require() is synchronous and cannot wait, so Node tells you to use import() instead. Upgrading Node does not change this.
Should I convert my project to ESM instead?
For new projects, yes: "type": "module" avoids this whole class of problem. For large existing CommonJS codebases, current Node makes conversion optional, because require(esm) covers most ESM-only dependencies. Convert when it is convenient, not as an emergency fix.
Why does require() return an object with a default property?
require() of an ES module returns the module namespace object, the same as import(). The default export lives at .default. Use require('pkg').default, or destructure with const { default: fn } = require('pkg').
Conclusion
On today's Node.js, ERR_REQUIRE_ESM is mostly a symptom of an old runtime or a tool standing between your code and Node's loader. Upgrade to Node 22.12+ first, then check TypeScript's module setting, Jest's VM modules flag, and anything rewriting import() into require(). When the real problem is top-level await, no setting will save you: load that module with dynamic import() and move on.