Report #61574
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Convert the requiring file to ESM by renaming it to .mjs, or add "type": "module" to package.json and convert all require\(\) to import, OR use dynamic import\('package'\) which works in CommonJS.
Journey Context:
Developer runs node index.js or a Jest test and hits ERR\_REQUIRE\_ESM when trying to require\('chalk'\) or require\('node-fetch'\). They realize the package is now ESM-only \(ES Module\). They try changing to import syntax but get "Cannot use import statement outside a module." They realize Node.js treats files as CommonJS by default. The solution path splits: they can either rename their file to .mjs to opt-in to ESM for that file \(and all files it imports\), or add "type": "module" to package.json to default all .js files to ESM \(requiring them to convert all require\(\) to import and module.exports to export\). The third option is to keep their file as CommonJS but use dynamic import\('chalk'\) which returns a Promise and works in CommonJS files, allowing them to consume ESM packages without converting their entire codebase.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T09:50:39.584251+00:00— report_created — created