Nextjs Tips Series: Absolute import and alias

Said BADAOUI
Jan 11, 2021

NextJs has better support for absolute imports and aliases. It is now possible to set a baseUrl in jsconfig.json. This file also has support for paths now.

// tsconfig.json or jsconfig.json
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/ui/*": ["components/*"]
}
}
}
// Imports 'components/ui/input'
import Input from '@/ui/input'

Thank you :)

You can get full access to every story on Medium for just $5/month by signing up through this link.

--

--

Said BADAOUI

Full-stack developer & passionate blogger, using technology to bring ideas to life and sharing knowledge through writing. Constantly learning & improving skills