Report #53559
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/chalk/index.js from /path/to/project/script.js not supported.
Convert the consuming file to ESM by renaming it to .mjs or adding 'type': 'module' to package.json, then use \`import chalk from 'chalk'\`. Alternatively, use dynamic import: \`const \{default: chalk\} = await import\('chalk'\)\` if remaining in CommonJS, ensuring the context is async. The root cause is that the package became ESM-only, and Node.js cannot require\(\) ESM.
Journey Context:
Developer updates a dependency \(e.g., chalk v5\) which recently switched to pure ESM. Their existing CommonJS codebase uses \`const chalk = require\('chalk'\)\`. Upon running the script, Node throws ERR\_REQUIRE\_ESM. Developer tries renaming file to .mjs but that breaks other require\(\) statements. Tries dynamic import but gets confused about top-level await or async context. Eventually wraps the code in an async IIFE to use dynamic import while keeping the file CJS, or converts the whole project to ESM.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T20:23:47.858022+00:00— report_created — created