Nextjs Tips Series: Absolute import and alias

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 :)

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store