Report #8356
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module ... not supported
Convert your file to ESM by renaming it to .mjs, or add "type": "module" to your package.json, or keep the file as CJS and use dynamic import\('package'\) to load the ESM module asynchronously.
Journey Context:
You npm install a modern library like chalk 5, node-fetch 3, or got 12 and try to require it in your existing CommonJS file: const chalk = require\('chalk'\). You immediately get ERR\_REQUIRE\_ESM. You inspect the library's package.json and see "type": "module". Node.js treats .js files as CommonJS by default. When you use require\(\) on an ES module, Node throws because ESM has different loading semantics \(static analysis, top-level await\) that cannot be synchronously required. To fix this, you have three paths: 1\) Convert your own project to ESM by adding "type": "module" to your package.json \(and converting all require\(\) to import/export\), 2\) Rename your specific file to .mjs to opt it into ESM, or 3\) Keep your file as CJS and use dynamic import\('chalk'\), which returns a Promise and is the only way to load ESM from CJS asynchronously.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T05:17:27.567659+00:00— report_created — created