Report #77763
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... is not supported. Instead change the require ... to a dynamic import\(\)
Convert the importing file to ESM by renaming to .mjs or adding "type": "module" to package.json, or replace require\(\) with await import\(\) for dynamic loading of ESM packages.
Journey Context:
Developer installs a modern npm package \(e.g., chalk 5, node-fetch 3, got\) in a CommonJS project. They write const chalk = require\('chalk'\) and run node index.js. Node throws ERR\_REQUIRE\_ESM. Developer checks the package's package.json and sees "type": "module". They try renaming index.js to index.mjs, but now all their other require\(\) calls and \_\_dirname references break. They realize they must either migrate the entire project to ESM \(update file extensions, change require to import, use import.meta.url for \_\_dirname\), or keep the file as CJS and use dynamic import\('chalk'\) which returns a Promise that resolves to the module namespace, allowing conditional or async loading of the ESM package from CJS code.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:07:42.078506+00:00— report_created — created