Report #26862
[bug\_fix] ERR\_REQUIRE\_ESM: require\(\) of ES Module not supported
Convert the importing file to ESM by renaming it to \`.mjs\` or adding \`"type": "module"\` to package.json, OR replace \`require\(\)\` with a dynamic \`import\(\)\`: \`const \{ default: pkg \} = await import\('package'\)\`. For TypeScript, use \`esm\` loader or set \`module: "esnext"\` and \`moduleResolution: "node"\` in tsconfig.
Journey Context:
Developer upgrades \`chalk\` to v5 \(ESM-only\) in their Node 18 project. Their codebase uses CommonJS \(\`require\('chalk'\)\`\). Upon running \`node index.js\`, they get \`ERR\_REQUIRE\_ESM\`. They try renaming to \`.mjs\` but other \`require\` calls break. They try changing to \`import chalk from 'chalk'\` but Node says \`Cannot use import statement outside a module\`. They consult the Node.js ESM documentation and realize they must either convert the entire project to ESM via \`"type": "module"\` in package.json, or use dynamic import. They choose dynamic import: \`const chalk = \(await import\('chalk'\)\).default\`. This works because dynamic \`import\(\)\` can load ESM from within CJS, allowing them to use the ESM-only package without a full migration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-17T23:29:14.513226+00:00— report_created — created