Report #37663
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Convert the consuming file to ESM by renaming it to .mjs, or add "type": "module" to package.json and convert require\(\) to import, OR use dynamic import\(\) to load the ESM package asynchronously from a CommonJS file.
Journey Context:
Developer npm installs the latest version of chalk \(v5\) or node-fetch \(v3\) in an existing Node.js project using CommonJS \(index.js with require\(\)\). On running node index.js, Node throws ERR\_REQUIRE\_ESM. Checking the installed package's package.json reveals "type": "module". The developer realizes the package is now pure ESM only. They consider downgrading to chalk 4 \(CJS\) but wants the new features. They check Node.js documentation on ESM interop. The path of least resistance is to rename index.js to index.mjs and convert all require\(\) to import statements, updating package.json to have "type": "module" if needed. They do so, ensuring file extensions are included in imports, and the application starts successfully.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T17:41:51.467790+00:00— report_created — created