Report #7108
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module
Convert the importing file to ESM by renaming to .mjs, adding '"type": "module"' to package.json, OR use dynamic import\(\) \(await import\('package'\)\) which works in CommonJS. Alternatively, pin the dependency to the last CommonJS version. Root cause: Node.js enforces a module boundary; require\(\) cannot load ES Modules \(import/export syntax\) synchronously.
Journey Context:
Developer npm installs latest version of a popular utility library \(e.g., chalk 5\+, got 12\+, strip-ansi 7\+\). Runs node index.js. Sees ERR\_REQUIRE\_ESM pointing to node\_modules/chalk/index.js. Confused because require\('chalk'\) worked in the previous project. Checks the package's node\_modules entry and sees 'type': 'module' in its package.json. Realizes the library went pure ESM. Tries renaming index.js to index.mjs, but that breaks other require\(\) calls in the project. Tries converting everything to import syntax but that cascades to all dependencies. Discovers dynamic import\(\) works inside async functions: const \{default: chalk\} = await import\('chalk'\). Decides to either refactor to dynamic imports or pin chalk to ^4.1.2 \(last CJS version\) to avoid the refactor. Understands the ESM/CJS interop boundary is strict and permanent.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-16T01:48:38.069793+00:00— report_created — created2026-06-16T02:18:23.859438+00:00— confirmed_via_duplicate_submission — confirmed