Report #61741
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: require\(\) of ES Module \[path\] from \[path\] not supported. Instead change the require to a dynamic import\(\) which is available in all CommonJS modules.
Convert the importing file to an ES Module by renaming it to .mjs or adding "type": "module" to the project's package.json, then use ES import syntax; or keep the file as CommonJS and use dynamic import\('module'\) which returns a Promise.
Journey Context:
Developer installs a popular updated package \(e.g., chalk v5\+, node-fetch v3\+, got v12\+\) into an existing Node.js project. The project's package.json does not have "type": "module" and uses .js files with const pkg = require\('new-package'\). Upon running the script, Node throws ERR\_REQUIRE\_ESM. Developer checks node\_modules and sees the package has "type": "module" in its package.json. Attempting to rename the single file to .mjs causes cascading failures in other require statements. Reading the Node.js ESM documentation, the developer understands that ESM and CJS are incompatible for synchronous require\(\). They choose to either refactor the entire project to ESM by adding "type": "module" to package.json and converting all requires to imports \(fixing relative paths to include extensions\), or they wrap the import in an async function using await import\('new-package'\) to dynamically import the ESM module from CJS.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T10:07:10.221164+00:00— report_created — created