Report #74176
[bug\_fix] ERR\_REQUIRE\_ESM when using require\(\) on ES-only packages like chalk 5, node-fetch 3, or got 12\+.
Convert to ESM by adding \`"type": "module"\` to package.json and renaming files to .js \(or .mjs\), or use dynamic import: \`const \{default: chalk\} = await import\('chalk'\)\`. Alternatively, downgrade to the CJS version of the package \(e.g., chalk 4.1.2\).
Journey Context:
You \`npm install chalk\` and write \`const chalk = require\('chalk'\)\`. On running the script, Node throws \`Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported\`. You check the chalk docs and see v5\+ is ESM-only. You try renaming your file to \`index.mjs\` and using \`import\`, but your entire codebase is CommonJS. You consider downgrading to chalk v4, but you want the new features. You finally refactor your entry point to use dynamic \`import\(\)\`, making the function async, which works because dynamic import is allowed in CJS files to load ESM.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T07:06:02.717988+00:00— report_created — created