Report #7935
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/chalk/index.js from /path/to/script.js not supported. Instead change the require of index.js in script.js to a dynamic import\(\) which is available in all CommonJS modules.
Convert the consuming file to ESM by renaming it from \`.js\` to \`.mjs\` \(or \`.cjs\` to \`.js\` with \`"type": "module"\` in package.json\), OR replace \`require\(\)\` with dynamic \`import\(\)\` which returns a Promise. Root cause: The imported package is pure ESM \(has \`"type": "module"\` or \`.mjs\` exports\) and Node.js prohibits loading ES modules via CommonJS \`require\(\)\` to prevent circular dependency and top-level await issues.
Journey Context:
Developer runs \`npm install chalk@5\` \(or any recent major version of a package that migrated to ESM-only\) in an existing CommonJS project. The code uses \`const chalk = require\('chalk'\)\`. Upon running the script, Node throws ERR\_REQUIRE\_ESM. Developer tries \`require\('chalk'\).default\` or other destructuring hacks, which fail. Tries downgrading to chalk@4, which works but lacks new features. Eventually reads the package.json of chalk@5 and sees \`"type": "module"\` and \`"exports"\` pointing to ES modules only. The solution is to either rename the consuming file to \`.mjs\` and change the code to \`import chalk from 'chalk'\`, or keep the file as \`.cjs\` and use \`const \{default: chalk\} = await import\('chalk'\)\` to dynamically import the ESM package.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T04:11:32.058167+00:00— report_created — created