DEV Community

Discussion on: Path Aliases in Next.js

Collapse
 
_genjudev profile image
Larson • Edited

Well this would not work and components will not be resolved.
Components are in your src folder. But the compilation is done in the root folder. You need to change it.

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

Or by changing the baseUrl

{
    "compilerOptions": {
        "baseUrl": "./src/",
        "paths": {
            "@/components/*": ["/components/*"]
        }
    }
}
Enter fullscreen mode Exit fullscreen mode
Collapse
 
gbotemi_dev profile image
gbotemi_dev

His approach worked fine for me. Your second approach of changing the baseUrl also worked fine. But your first approach didn't work.

Collapse
 
mbappai profile image
Mujahid Bappai

I think his solution will work for him since his component folder is directly under the root folder.