Report #70775
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Convert consuming file to ES Module \(.mjs extension or 'type': 'module' in package.json\) and use import syntax, or use dynamic import\(\) for ESM packages in CJS files.
Journey Context:
Developer upgrades chalk from v4 to v5 \(or got, ora, node-fetch v3\). Their existing CommonJS code uses const chalk = require\('chalk'\). Immediately crashes with ERR\_REQUIRE\_ESM, noting the package is an ES Module. Confused because their package.json doesn't have 'type': 'module'. They realize the dependency itself is pure ESM. Attempting const chalk = await import\('chalk'\) in a CJS file fails because top-level await isn't available in CJS modules. They must either convert the file to .mjs and use import chalk from 'chalk', or use dynamic import\(\) inside an async function: const \{ default: chalk \} = await import\('chalk'\).
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T01:22:20.077940+00:00— report_created — created