It looks like you're encountering a "Module not found" error when trying to import a component using a module path alias in Next.js 14.2.4. This issue is often related to the configuration of module path aliases in your project.
Next.js supports Module Path Aliases (https://nextjs.org/docs/app/building-your-application/configuring/absolute-imports-and-module-aliases) to make it easier to manage imports in deeply nested project files. However, if these aliases are not correctly configured, you will encounter errors like the one you're seeing.
Here's how you can configure module path aliases in your jsconfig.json or tsconfig.json file:
-
Create or Update jsconfig.json or tsconfig.json:
Ensure you have a jsconfig.json or tsconfig.json file at the root of your project. If you don't have one, create it.
-
Add Path Aliases Configuration:
Add the following configuration to your jsconfig.json or tsconfig.json file to define the path aliases:
{
"compilerOptions": {
"baseUrl": ".",
"paths": {
"@/components/*": ["components/*"],
"@/config/*": ["config/*"],
"@/errors/*": ["errors/*"]
}
}
}
This configuration tells the compiler where to find the modules when you use the @/ prefix.
-
Restart Your Development Server:
After updating the configuration, restart your Next.js development server to apply the changes.
Here is an example of how your import statements should look after configuring the path aliases:
import { Button } from '../../../components/ui/button'
import { Button } from '@/components/ui/button'