Report #103687
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/package/index.mjs from /path/to/file.js not supported.
Use \`import\(\)\` \(dynamic import\) instead of \`require\(\)\`, or change the importing file to an ES module by setting \`"type": "module"\` in its \`package.json\` or renaming to \`.mjs\`. Alternatively, if the package provides a CommonJS entry, use that.
Journey Context:
A developer migrated a Node.js project to use ES modules by adding \`"type": "module"\` in \`package.json\`. They then tried to \`require\('lodash'\)\` in a \`.js\` file, but Lodash is CommonJS and worked. Later they installed a package that was pure ESM \(e.g., \`chalk@5\`\). The \`require\(\)\` call threw ERR\_REQUIRE\_ESM. The developer learned that \`require\(\)\` cannot load ES modules synchronously. The fix was to change the \`require\(\)\` to a dynamic \`import\(\)\` and handle the promise, or use \`.cjs\` extension for the file that needs CommonJS. The root cause is the dual module system in Node.js: ESM and CommonJS are not fully interoperable in synchronous contexts.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-12T20:04:28.889481+00:00— report_created — created