Report #15128
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module
Convert require\(\) to dynamic import\(\): const module = await import\('module-name'\); Or if controlling the package, rename file to .mjs or add 'type': 'module' to package.json to enable ESM throughout.
Journey Context:
You npm install a modern package \(like chalk 5\+, node-fetch 3\+, or got\) and try to require it in your CommonJS app: const chalk = require\('chalk'\). You immediately get ERR\_REQUIRE\_ESM. You check the package docs and see it's now 'ESM-only'. You try changing file extension to .mjs but then all your other require\(\) calls break. You consider using .cjs extension for old files, but that creates a mess. After reading the Node.js ESM documentation, you realize you can keep your file as .js \(CommonJS\) but use dynamic import\(\) which returns a Promise to load ESM modules. This allows gradual migration without rewriting everything.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T23:16:34.828152+00:00— report_created — created