Report #13230
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module
Convert to ESM by renaming file to .mjs, adding "type": "module" to package.json, or use dynamic import\(\) instead of require\(\). Alternatively, stay on the CommonJS version of the dependency. Root cause: Node.js enforces that ES modules \(ESM\) cannot be loaded with require\(\), only import statements or dynamic import\(\).
Journey Context:
Developer runs npm update which bumps 'got' \(or 'chalk', 'node-fetch'\) to latest version. Their existing script does const got = require\('got'\) and suddenly throws 'ERR\_REQUIRE\_ESM: require\(\) of ES Module'. Developer checks the package changelog and sees 'Now pure ESM'. They try renaming their file to .mjs but then all their other require\(\) calls break. They try adding "type": "module" to package.json but that breaks their entire codebase. They consider downgrading to the old version. Eventually they refactor to use dynamic import: const \{ default: got \} = await import\('got'\). They realize ESM is the future but requires architectural changes to adopt.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T18:13:35.394788+00:00— report_created — created