Report #101431
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
If the consuming project is CommonJS, downgrade the imported package to a version that still ships CommonJS, or convert your project to ESM by adding \`"type": "module"\` to \`package.json\` and renaming \`.js\` files to \`.cjs\`/\`.mjs\` where needed. As a last resort, use dynamic \`import\(\)\` inside an async CommonJS function, since dynamic \`import\(\)\` can load ESM modules.
Journey Context:
A Node script written as CommonJS does \`const chalk = require\('chalk'\)\` after \`npm install chalk\`. On \`chalk@5\` it crashes with \`ERR\_REQUIRE\_ESM: require\(\) of ES Module ... is not supported\`. The developer checks \`node\_modules/chalk/package.json\` and sees \`"type": "module"\`. They first try changing \`require\` to \`import\` in the same \`.js\` file, but Node throws \`Cannot use import statement outside a module\`. They consider renaming the file to \`.mjs\`, but that breaks other \`require\(\)\` calls in the same file. The cleanest established fix is either to pin \`chalk@4\` \(the last CommonJS line\) or to convert the whole package to ESM by setting \`"type": "module"\` in \`package.json\`. The error exists because Node enforces a strict separation: \`require\(\)\` is synchronous and cannot execute ESM's top-level await or static resolution graph, so ESM packages cannot be \`require\(\)\`d.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-07T04:50:31.882240+00:00— report_created — created