Report #10970
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/chalk/index.js from /path/to/project/index.js is not supported. Instead change the require of index.js to a dynamic import\(\) which is available in all CommonJS modules.
Convert the importing file to ESM by renaming it to .mjs or adding "type": "module" to package.json, or replace require\(\) with await import\(\) \(dynamic import\).
Journey Context:
Developer installs the latest version of a popular utility like chalk v5 or node-fetch v3 in an existing Node.js project. Their code uses const fetch = require\('node-fetch'\). Upon running the script, Node throws ERR\_REQUIRE\_ESM. The developer checks the package documentation and sees it is now "ESM-only". They try renaming the file to .mjs, but then all other require\(\) calls in the project break. They consider rewriting everything to ESM but that is too invasive. They discover that dynamic import\(\) is allowed in CommonJS files and returns a Promise. They refactor to const \{default: fetch\} = await import\('node-fetch'\), which works immediately because it defers loading until runtime, satisfying Node's ESM loader constraints without a full migration.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T12:12:48.644717+00:00— report_created — created