Next.js path aliases resolve identically whether the target is a file or a directory with index.ts
1 min read
I split src/lib/i18n.ts into src/lib/i18n/index.ts + ja.ts + en.ts for better maintainability. None of the 50+ files importing from @/lib/i18n needed changes.
src/lib/i18n.ts ← @/lib/i18n resolves heresrc/lib/i18n/
index.ts ← @/lib/i18n resolves here (same path)
ja.ts
en.tsNode.js module resolution first looks for i18n.ts, then falls back to i18n/index.ts. As long as exports are preserved, migrating from a single file to a directory is fully transparent. Zero import changes, zero test updates.
