DEV Community

Alexander Kim
Alexander Kim

Posted on

3 2

Path aliases in Nextjs

Tired of writing such imports?

import test from '../../../components/Test.tsx';
Enter fullscreen mode Exit fullscreen mode

If you're using a typescript, you can create a path alias instead:

{
  "compilerOptions": {
    "baseUrl": "src",
    "paths": {
      "@/*": ["./*"] 
    }
  }
}
Enter fullscreen mode Exit fullscreen mode

Then you can import more conveniently:

import test from '@/components/Test.tsx';
Enter fullscreen mode Exit fullscreen mode

Don't forget to restart your running task to affect changes.

Top comments (0)

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay