Report #80502
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported. Instead change the require of index.js to a dynamic import\(\)
Replace const pkg = require\('package'\) with const \{default: pkg\} = await import\('package'\), or convert the consuming file to an ES module by renaming it to .mjs or adding "type": "module" to package.json.
Journey Context:
A developer runs npm update which upgrades chalk to v5 or node-fetch to v3, both now pure ESM packages. The existing codebase uses const chalk = require\('chalk'\). On the next application start, Node crashes with ERR\_REQUIRE\_ESM. The developer is confused because the import worked yesterday. Checking node\_modules reveals chalk now has "type": "module" in its package.json. The developer tries renaming the file to .mjs but that breaks other CommonJS requires in the codebase. Eventually, they change the code to use const chalk = \(await import\('chalk'\)\).default, which works because dynamic import can load ESM from CJS files, though it requires refactoring to async context.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T17:43:48.074020+00:00— report_created — created