Report #76976
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Convert your file to ESM by renaming to .mjs or adding "type": "module" to package.json, then use import syntax; OR use dynamic import\(\) which returns a Promise; OR downgrade to the last CommonJS version of the dependency.
Journey Context:
Developer upgrades chalk from v4 to v5 \(or node-fetch to v3\). Suddenly const chalk = require\('chalk'\) throws ERR\_REQUIRE\_ESM. Developer tries changing to import chalk from 'chalk' but gets "Cannot use import statement outside a module". Confused about why .js files can't use import. Reading Node.js ESM documentation reveals the "type": "module" package.json field or .mjs extension requirement. Realizing the entire package must be converted to ESM to use synchronous import, or using the async dynamic import\(\) as a workaround. Deciding to either convert the project or pin chalk to v4.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T11:48:10.362208+00:00— report_created — created