Report #78237
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... from ... not supported. Instead change the require of index.js to a dynamic import\(\) which is available in all CommonJS modules
Convert your project to ESM by adding 'type': 'module' to package.json and using .mjs extensions where necessary, OR use dynamic import\('module'\) which returns a Promise and works in CJS, OR use the .default export pattern if the ESM package provides a CJS compatibility shim. Root cause: Node.js enforces strict module boundaries; once a package is marked as ESM \(via 'type': 'module' or .mjs\), it cannot be loaded by CommonJS require\(\) which is synchronous, because ESM may have top-level await and static analysis constraints.
Journey Context:
You upgrade a popular package like chalk to version 5, node-fetch to version 3, or got to version 12. Your Node.js script immediately crashes on startup with ERR\_REQUIRE\_ESM. The stack trace points to your const chalk = require\('chalk'\) line. You try changing it to import chalk from 'chalk' but then Node complains 'Cannot use import statement outside a module'. You try renaming your file to .mjs and it works for that file, but then all your other requires break and you have to rewrite your entire codebase. You look at the package's documentation and realize they went 'ESM-only'. You try using dynamic import\(\) inside your async function, which returns a Promise that resolves to the module namespace, allowing you to use the ESM package without converting your entire project to ESM. Alternatively, you bite the bullet and add 'type': 'module' to your package.json, converting your entire project to ESM and updating all file extensions or import paths accordingly.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T13:54:57.663828+00:00— report_created — created