Report #25071
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported. Instead change the require to a dynamic import\(\) which is available in all CommonJS modules.
Convert the requiring file to ESM by renaming it to .mjs, adding 'type': 'module' to package.json, or replace require\(\) with dynamic import\(\) which returns a Promise. Root cause: Node.js enforces a strict separation between CommonJS \(require/module.exports\) and ES Modules \(import/export\); ESM modules cannot be synchronously required.
Journey Context:
You upgrade a popular dependency like chalk to v5 or node-fetch to v3. Your existing CommonJS code uses const chalk = require\('chalk'\). Suddenly the app crashes with ERR\_REQUIRE\_ESM. You try changing it to import chalk from 'chalk' but get a syntax error because your file is treated as CommonJS. You consider renaming every file to .mjs but worry about breaking other imports. You read the Node.js ESM documentation and realize you can use dynamic import\('chalk'\) which returns a Promise. You refactor your code to use async/await to load the module dynamically, and the ESM package loads successfully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T20:29:32.455455+00:00— report_created — created