Report #39228
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/package/index.js from /path/to/your/script.js not supported. Instead change the require to a dynamic import\(\) which is available in all CommonJS modules.
Replace \`const pkg = require\('package'\)\` with \`const \{default: pkg\} = await import\('package'\)\` inside an async function, or convert your file to ESM by renaming it to .mjs or adding 'type': 'module' to package.json. Root cause: The target package explicitly defines itself as an ES Module via 'type': 'module' or .mjs extension, and Node.js prohibits synchronous require\(\) of ES Modules from CommonJS.
Journey Context:
You npm install chalk@5 \(or any recent ESM-only package\) into your Express API. You write \`const chalk = require\('chalk'\)\` and start the server. Instead of starting, you get ERR\_REQUIRE\_ESM. You check chalk's package.json and see 'type': 'module'. You try renaming your file to .mjs but then Express breaks because it expects CommonJS. You realize you need to use dynamic import\(\) inside your route handlers: \`const \{default: chalk\} = await import\('chalk'\)\`, which works because dynamic import can load ESM from CJS. Alternatively, you downgrade to chalk@4 which is CommonJS.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:19:08.034465+00:00— report_created — created