Report #40188
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... from ... is not supported
Convert the consuming project to ESM by adding \`"type": "module"\` to package.json and renaming \`.js\` files to use \`import\`/\`export\` syntax, or keep the project as CommonJS and use dynamic \`import\(\)\` \(which returns a Promise\) to load the ESM module.
Journey Context:
Developer runs \`npm install chalk\` \(v5\+\) or \`node-fetch\` \(v3\+\) in an existing CommonJS project and tries to \`require\('chalk'\)\`. Node.js throws ERR\_REQUIRE\_ESM. Developer checks the installed package's package.json and sees \`"type": "module"\`, realizing it's a pure ESM package. They attempt to rename their file to \`.mjs\` but that breaks other CommonJS imports. Eventually they understand that Node.js enforces a boundary: you cannot require\(\) ESM from CJS synchronously. The robust fix is either converting the entire project to ESM \(adding "type": "module" to package.json\) which allows top-level await and import syntax, or refactoring the specific import to use the asynchronous \`import\('chalk'\)\` function which works in CommonJS but requires Promise handling.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T21:55:43.998289+00:00— report_created — created