Report #14004
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... from ... not supported.
Convert the requiring file to ESM \(rename to .mjs or add "type": "module" to package.json\) and use import syntax, or use dynamic import\(\) which returns a Promise, or downgrade to a CommonJS-compatible version of the dependency. Root cause: Node.js enforces a strict separation between CommonJS \(require/module.exports\) and ES Modules \(import/export\); require\(\) cannot load ES modules because ES modules have a static analysis phase and different loading semantics.
Journey Context:
A developer maintains an Express API using CommonJS \(index.js with require\('express'\)\). They npm install got to make HTTP requests \(installing got v13, which is ESM-only\). They add const got = require\('got'\) and run node index.js. Immediate crash: ERR\_REQUIRE\_ESM. The developer checks the got documentation and sees "ESM only". They try renaming index.js to index.mjs, but then all require\(\) calls break with "ReferenceError: require is not defined". They consider using createRequire but realize that's complex. They try const got = await import\('got'\) inside an async function, which works because dynamic import\(\) can load ESM from CJS, but now they have to refactor all their code to be async. Ultimately, they either \(1\) convert the entire project to ESM by adding "type": "module" to package.json and rewriting all requires to imports, or \(2\) downgrade to got v11.8 which supports CommonJS, accepting the security/bugfix debt. The fix works because it resolves the module system mismatch—either by moving fully to ESM where import is native, or by using dynamic import\(\) which is the interoperability bridge defined in the Node.js ESM specification.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T20:21:19.304121+00:00— report_created — created