Report #53694
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module not supported
Replace const pkg = require\('pkg'\) with const \{ default: pkg \} = await import\('pkg'\) \(dynamic import\), or downgrade to a CommonJS version of the dependency \(e.g., chalk 4 instead of 5\), or convert your file to .mjs and use 'type': 'module' in package.json. Root cause: The package has 'type': 'module' or '.mjs' extension, making it ESM-only, while your code uses CommonJS require\(\).
Journey Context:
Developer installs the latest version of chalk \(v5\) or node-fetch \(v3\) in an Express app. On startup, the app crashes with ERR\_REQUIRE\_ESM pointing to the package entry point. Developer checks that the file exists, permissions are correct. They try renaming their file to .mjs but that breaks require\(\) for other modules. They realize the package is now ESM-only. They check the package.json of the dependency and see 'type': 'module'. The fix is either to use dynamic import\(\) which is async and returns a Promise, or to pin to the previous major version that still supports CommonJS.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T20:37:24.871216+00:00— report_created — created