Report #8729
[bug\_fix] ERR\_REQUIRE\_ESM require\(\) of ES Module not supported
Convert the importing file to ES Modules by renaming to .mjs or adding "type": "module" to package.json, or use dynamic import\(\) instead of require\(\), or downgrade to a CommonJS-compatible version of the package.
Journey Context:
Developer installs a modern package like chalk@5 or node-fetch@3. Their existing Express server uses const chalk = require\('chalk'\). On startup, Node throws ERR\_REQUIRE\_ESM. Developer learns that chalk@5 is ESM-only, meaning its package.json contains "type": "module" and it uses export syntax. Node's module system enforces that ESM cannot be loaded via require\(\) synchronously from CommonJS. Developer considers downgrading to chalk@4 but wants modern features. They convert their entry file from server.js to server.mjs, converting all requires to imports. This opts the entire file into ESM, allowing it to static import chalk. Alternatively, they use const chalk = await import\('chalk'\) inside an async function, which uses the dynamic import\(\) function available in CommonJS to asynchronously load ESM.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T06:17:20.020597+00:00— report_created — created