Report #70287
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: Must use import to load ES Module: /path/to/node\_modules/chalk/source/index.js
Use dynamic import in the CommonJS file: \`const \{ default: chalk \} = await import\('chalk'\);\` inside an async function or at module top level if the file is ESM. Alternatively convert the consuming file/package to ESM by using the \`.mjs\` extension or adding \`"type": "module"\` to package.json.
Journey Context:
You have a CLI tool written in CommonJS that does \`const chalk = require\('chalk'\);\`. After running \`npm update\`, chalk becomes a pure ESM package and your script crashes with \`ERR\_REQUIRE\_ESM\`. You try \`require\('chalk'\).default\`, but Node throws the same error because \`require\(\)\` cannot load ESM at all. You read the Node.js error docs and see that ESM must be loaded via \`import\`. You refactor the file to an async function and use \`await import\('chalk'\)\`, which works because dynamic \`import\(\)\` is supported in both CommonJS and ESM and returns the module namespace. The CLI runs again without pinning an old chalk version.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T00:33:14.424218+00:00— report_created — created