Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
#140Error
Error [ERR_REQUIRE_ESM]: require() of ES Module .../node_modules/some-pkg/index.js from .../app.js not supported. Instead change the require of index.js to a dynamic import()
Why it happens, and why this works
Older Node versions can't load an ES module synchronously with require(), and many popular packages dropped their CommonJS build in new majors. import()/ESM, an older CJS major, or a Node version with require(esm) all avoid the synchronous load.
Fix
The package is ESM-only; load it the ESM way (or pin its last CommonJS version).
1. Best: make your project ESM: add "type": "module" to package.json and switch require() to import (rename config files that must stay CJS to .cjs).
2. Staying CommonJS: load it with dynamic import inside an async function: const { default: pkg } = await import('some-pkg')
3. Or install the last CJS major (e.g. node-fetch@2, chalk@4, nanoid@3, got@11).
4. Node 22.12+/20.19+ can require() most ESM packages directly; upgrading Node also fixes it unless the module uses top-level await.Did it work?
No reports yetKnown good on: node@18, before@20.19
Related fixes
ReferenceError: require is not defined in ES module scope
#23ReferenceError: require is not defined in ES module scope, you can use import instead
ImportError: cannot import name from partially initialized module (circular import)
#52ImportError: cannot import name 'User' from partially initialized module 'models' (most likely due to a circular import). Python 3.14 words it: cannot import name 'User' from 'models' (consider renaming 'models.py' if it has the same name as a library you intended to import)
node --test can't import project files: Cannot use import statement outside a module
#7SyntaxError: Cannot use import statement outside a module (or ERR_REQUIRE_ESM) when running node --test against lib/*.js files that use import/export.