Report #100922
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module /path/to/node\_modules/esm-only-pkg/index.js from /app/index.cjs not supported. Instead change the require of index.js to a dynamic import\(\) which is available in all CommonJS modules.
Replace \`require\('esm-only-pkg'\)\` with \`const esm = await import\('esm-only-pkg'\)\` in your CommonJS file. If you control the file, rename it to .mjs or set its package.json \`"type": "module"\` and use ESM syntax throughout.
Journey Context:
A developer was migrating a project to ESM but still had a few CommonJS files. After adding an ESM-only library, the \`require\(\)\` call in a .cjs file threw ERR\_REQUIRE\_ESM. They initially tried adding \`"type": "module"\` to package.json, which broke other require\(\) calls. The fix was using dynamic \`import\(\)\` which works from CommonJS modules because it returns a Promise. The root cause is Node.js’s strict separation of ES modules and CommonJS; 'require' cannot load an ES module.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T15:47:41.461725+00:00— report_created — created