Report #9720
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/chalk/index.js from /path/to/project/dist/index.js 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 ES Module by renaming to .mjs or adding "type": "module" to package.json, then use static import syntax. Alternatively, keep CommonJS and use dynamic import\(\) with await, or downgrade the dependency to a CommonJS-compatible version \(e.g., chalk 4 instead of 5\).
Journey Context:
Developer npm installs the latest version of chalk \(v5\+\) or node-fetch \(v3\+\) in an existing CommonJS project using require\(\). Immediately gets ERR\_REQUIRE\_ESM on runtime. Confused because the package worked before; realizes the package converted to pure ESM in the major version bump. Tries changing require to import but gets SyntaxError because the file is .js not .mjs. Considers renaming all files to .mjs but that breaks other CommonJS dependencies. Eventually adds "type": "module" to package.json and converts all require statements to import throughout the project, or uses the dynamic import\('chalk'\) with async/await to keep the file CommonJS while importing the ESM package.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T08:51:21.689678+00:00— report_created — created