Report #57926
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Replace require\(\) with dynamic import\(\) which returns a Promise, or convert your file to ESM \(.mjs or "type": "module"\) and use static import syntax.
Journey Context:
You npm install chalk@5 \(or node-fetch@3, or got@12\) in your existing Node.js project that uses CommonJS \(require/module.exports\). When you run const chalk = require\('chalk'\), Node.js throws ERR\_REQUIRE\_ESM. You check node\_modules/chalk/package.json and see "type": "module" and "exports" pointing to an ES module file. You check the Node.js documentation and learn that ES modules cannot be loaded synchronously via require\(\) because they have a different loading phase and top-level await. You consider downgrading to chalk@4 \(CommonJS\), but instead refactor your code to use dynamic import: const \{ default: chalk \} = await import\('chalk'\). This works because dynamic import\(\) is asynchronous and can load both CJS and ESM modules, allowing you to use the latest version of the package without converting your entire codebase to ESM.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T03:43:07.888155+00:00— report_created — created