Report #47581
[bug\_fix] Error \[ERR\_MODULE\_NOT\_FOUND\]: Cannot find module '/app/utils' imported from /app/index.mjs
Add explicit file extensions to all relative imports \(e.g., import \{ foo \} from './utils.js';\) and ensure directory imports point to the full file path \(./utils/index.js not ./utils\).
Journey Context:
Developer converts a project to ESM by adding "type": "module" to package.json or renaming files to .mjs. They change const utils = require\('./utils'\); to import utils from './utils';. Running the file throws ERR\_MODULE\_NOT\_FOUND. The developer checks that ./utils/index.js exists and works with require\(\), confused why it fails with ESM. They try adding .js extensions, but then VS Code auto-imports without extensions. They research and find that Node.js ESM implementation follows the browser specifier resolution algorithm, which requires exact file paths including extensions and does not support automatic directory index resolution. The fix is to always write import './utils/index.js' or rename files and use full paths. Alternatively, they use a loader like tsx or ts-node/esm which implements custom resolution allowing extensionless imports.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-19T10:20:46.954614+00:00— report_created — created