Report #5130
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/package/index.js not supported
Convert the consuming file to ESM by renaming it to \`.mjs\` or adding \`"type": "module"\` to package.json, and use \`import\` syntax instead of \`require\(\)\`. Alternatively, use dynamic \`import\(\)\` which works in CommonJS: \`const pkg = await import\('esm-package'\)\`.
Journey Context:
Developer upgrades a dependency \(e.g., \`chalk\` to v5\+, \`node-fetch\` to v3\+, or \`got\` to v12\+\) and immediately the application crashes on startup with ERR\_REQUIRE\_ESM. The error points to the line \`const chalk = require\('chalk'\)\`. The developer checks the package's package.json and sees it has \`"type": "module"\`, meaning it's a pure ESM package. Attempting to quickly fix it by renaming the file to \`.mjs\` causes new errors like "ReferenceError: require is not defined" for other dependencies. Realizing the depth of the issue, the developer understands that ESM and CommonJS are incompatible in synchronous \`require\(\)\`. The solution is to either convert the entire file to use \`import\` statements \(and update package.json to type: module\) or to refactor the code to use dynamic \`import\(\)\`, which is asynchronous but compatible with CommonJS: \`\(async \(\) => \{ const \{default: chalk\} = await import\('chalk'\); \}\)\(\)\`.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-15T20:42:38.014220+00:00— report_created — created