Report #40563
[bug\_fix] Error \[ERR\_MODULE\_NOT\_FOUND\]: Cannot find module '/path/to/file' imported from /path/to/index.js
Add explicit file extensions \(.js\) to all relative import specifiers in ESM code, or use a loader like tsx that handles resolution.
Journey Context:
Developer migrates a project to native ESM \("type": "module"\). They convert const utils = require\('./utils'\) to import \{ helper \} from './utils'. Immediately Node crashes with ERR\_MODULE\_NOT\_FOUND pointing to ./utils. The file ./utils.js definitely exists. The developer spends an hour checking file permissions and paths. They realize that unlike CommonJS, the ESM specification requires complete URLs including file extensions for relative imports. The import must be from './utils.js' \(even when importing TypeScript, the specifier must use .js which resolves to the emitted .js file\). The fix is to add .js to every relative import. In TypeScript projects, this means writing import from './utils.js' even though the source file is .ts. Alternatively, using a resolution loader or sticking to CommonJS avoids this.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T22:33:28.065683+00:00— report_created — created