Report #81644
[bug\_fix] Error \[ERR\_REQUIRE\_ESM\]: Must use import to load ES Module
Use dynamic import\(\) instead of require\(\), or convert your file to ESM by renaming to .mjs or adding "type": "module" to package.json
Journey Context:
You require\(\) a popular package like 'got' or 'node-fetch' v3\+ and Node crashes with 'ERR\_REQUIRE\_ESM: Must use import to load ES Module'. You check the package documentation and see it became ESM-only. You try renaming your file to .mjs but then all your require\(\) calls break. You realize you cannot require\(\) an ES module synchronously. You refactor to use dynamic import\('got'\) which returns a Promise and allows you to load the ESM module asynchronously from your CommonJS file. Alternatively, you convert your entire project to ESM by adding "type": "module" to package.json and changing all require\(\) to import, which allows you to use the package natively.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-21T19:38:11.700647+00:00— report_created — created