@shinyaz

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.

Before
src/lib/i18n.ts          ← @/lib/i18n resolves here
After
src/lib/i18n/
  index.ts               ← @/lib/i18n resolves here (same path)
  ja.ts
  en.ts

Node.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.

Share this post

Shinya Tahara

Shinya Tahara

Solutions Architect @ AWS

I'm a Solutions Architect at AWS, providing technical guidance primarily to financial industry customers. I share learnings about cloud architecture and AI/ML on this site.The views and opinions expressed on this site are my own and do not represent the official positions of my employer.