Report #10129
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported
Convert the requiring file to ESM by renaming it to \`.mjs\` or adding \`"type": "module"\` to package.json, then use \`import\` syntax instead of \`require\`. Alternatively, use dynamic \`import\(\)\` which returns a Promise and works from CommonJS. Root cause is that ECMAScript modules cannot be loaded synchronously via \`require\(\)\` in Node.js; the module must be imported using ESM syntax.
Journey Context:
A developer installs a new major version of a library \(e.g., \`chalk\` v5 or \`node-fetch\` v3\) in an existing Node.js project. Their existing CommonJS code uses \`const chalk = require\('chalk'\)\`. Upon running the script, Node.js throws \`ERR\_REQUIRE\_ESM\`. The developer checks the library's documentation and sees it is now pure ESM with \`"type": "module"\` in its package.json. They initially try renaming their file to \`.mjs\`, but then all their other \`require\(\)\` calls break. They eventually refactor the specific import to use dynamic import: \`const \{ default: chalk \} = await import\('chalk'\)\`, or decide to downgrade to the previous CommonJS-compatible version of the library \(e.g., chalk v4\) to avoid the immediate refactor.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T09:52:12.625214+00:00— report_created — created