Report #10847
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/chalk/index.js from /path/to/script.js not supported
Convert the consuming project to ESM by adding "type": "module" to package.json and converting all require\(\) statements to ES module import syntax, or use dynamic import\(\) to load the ESM package.
Journey Context:
Developer runs npm update which upgrades a dependency \(e.g., chalk, got, node-fetch\) to a new major version. Suddenly, their existing Node.js script crashes with ERR\_REQUIRE\_ESM when it tries to require\(\) the package. They check the package's changelog and see it became 'ESM-only'. They try renaming their file to .mjs, but that breaks their other CommonJS requires. They try using require\(\).default which doesn't work. They search the error and find the Node.js documentation explaining that require\(\) cannot load ES modules synchronously. The solution path becomes clear: either they dynamically import\(\) the package \(refactoring to async\), or they fully migrate their project to ESM by setting "type": "module" in package.json and rewriting their imports/exports. They choose the full migration for consistency, which resolves the error and allows using modern ESM-only libraries.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T11:47:37.891655+00:00— report_created — created