Report #12211
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/chalk/index.js from /path/to/project/server.js not supported. Instead change the require of index.js in /path/to/project/server.js to a dynamic import\(\) which is available in all CommonJS modules.
Replace the require\(\) statement with a dynamic import\(\) \(e.g., const chalk = \(await import\('chalk'\)\).default;\), or convert the importing file to an ES Module by renaming it to .mjs or adding "type": "module" to package.json.
Journey Context:
Developer npm installs latest version of chalk \(v5\+\) or node-fetch \(v3\+\) in an existing Express.js project using CommonJS \(require/module.exports\), upon starting the app gets ERR\_REQUIRE\_ESM crash. They check the installed package files and see they use export default instead of module.exports, realize the package has gone pure ESM. They consider downgrading but want new features, debate converting entire codebase to ESM \(adding "type": "module" and changing all require to import\), decides to use dynamic import\(\) as a bridge solution to keep CommonJS entry point while loading the ESM package asynchronously.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T15:19:38.870549+00:00— report_created — created