Report #66680
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: Must use import to load ES Module
Convert file to .mjs, add 'type': 'module' to package.json, or use dynamic import\(\) to load the ESM package from CommonJS
Journey Context:
Developer installs chalk 5 or node-fetch 3 and tries const chalk = require\('chalk'\). Immediately crashes with ERR\_REQUIRE\_ESM. Tries renaming file to .mjs but that breaks other require\(\) calls. Considers downgrading. Learns they can use dynamic import: const \{default: chalk\} = await import\('chalk'\) but requires async context. Or adds 'type': 'module' to package.json and converts entire codebase to ESM, dealing with \_\_dirname issues via import.meta.url. The fix depends on whether they want to migrate to ESM or stay in CJS with dynamic imports.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T18:23:58.603062+00:00— report_created — created