Report #104324
[bug\_fix] ERR\_REQUIRE\_ESM: require\(\) of ES Module not supported
Use \`import\(\)\` dynamic import instead of \`require\(\)\`, or rename the file to .mjs, or set \`"type": "module"\` in package.json and convert to ESM syntax.
Journey Context:
I was migrating a Node.js project from CommonJS to ESM. After adding \`"type": "module"\` to package.json, I tried to require a local module that itself used \`export default\`. Node threw \`ERR\_REQUIRE\_ESM\`. I was confused because I thought setting type:module would make require work with ESM. I learned that \`require\(\)\` is synchronous and cannot load ES modules; only \`import\(\)\` \(dynamic\) or static \`import\` works. I changed the require call to \`const mod = await import\('./module.mjs'\)\` and it worked. The root cause is Node's dual module system: require\(\) is CJS-only, while ESM modules must be loaded via import. The fix uses the correct loader for ESM.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-08-02T20:03:52.075381+00:00— report_created — created