Error: Unable to locate module '@/components/Header' in Next.js project

I'm currently facing an issue while working on my Next.js project. The problem arises when I attempt to import a component into my 'page.js' file. In the 'src' folder, I have a subdirectory named 'components' which contains a file called 'Header.js'. Within this file, there is a function component called 'Header'. My import statement in 'page.js' looks like this:

import Header from "@/components/Header";

However, I am encountering the following error: Module not found: Can't resolve '@/components/Header'

I have double-checked to ensure that the file exists in the correct location and that the path is accurate. For reference, here is the structure of my project:

src/
├── components/
│   └── Header.js
└── pages/
    └── page.js

Header.js

export default function Header() {
  return(
    <header className="bg-white border-b flex justify-between p-4">
        <div className='flex gap-6'>
        <Link href={'/'}>Linkify</Link>
        <nav className='flex items-center gap-4 text-slate-500 text-sm'>
          <Link href={'/about'}>About</Link>
          <Link href={'/pricing'}>Pricing</Link>
          <Link href={'/contact'}>Contact</Link>
        </nav>
        </div>
        <nav className='flex items-center gap-4 text-sm text-slate-500'>
          <Link href={'/login'}>Sign In</Link>
          <Link href={'/register'}>Create Account</Link>
        </nav>
      </header>
  )
}

page.js

import Header from "@/components/Header";


export default function Home() {
  return (
    <main>
      <Header />
      <section>

      </section>
    </main>
    
  )
}

If you have any suggestions or solutions, your help would be greatly appreciated. Thank you!

Answer №1

If you want to utilize this feature, make sure to set up the alias path for @ within the specific file called tsconfig.json. Consider including the following configuration:

{   compilerOptions: {
      ...
      "paths": {
         "@/*": [
           "./*" // -> modify the path to your desired location
         ]
      },    
    }
}

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Correctly formatted onclick

How should I go about this? $chatterhtml .= '<span style="float:right;" > <a href="javascript:void(0);" onClick="deletecmnt(this, "'.$val['id'].'", "'.BASE_URL.'");" title="Delete Chatter">x</a&g ...

After installing grunt, the Gruntfile cannot be located. How can this issue be resolved?

After installing grunt, I encountered a problem. Despite trying some commands suggested on stackoverflow in this How to install grunt and how to build script with it, running the grunt command still shows the same result. What steps should I take next?ht ...

Using AngularJS to send a $http.post request with Paypal integration

This form utilizes the standard PayPal format for making purchases. <form action="https://www.paypal.com/cgi-bin/webscr" method="post"> <input type="hidden" name="cmd" value="_xclick"> <input type="hidden" name="business" value="<a href= ...

PHP: the images uploaded are not located within the designated folder

Having trouble uploading multiple images to a folder and saving them in the database? The images are not moving to the folder, even though the code works on localhost. Here is the code snippet: var abc = 0; // Declaring and defining global incremen ...

Update the CSS styling of a parent div based on the active state of specific child divs

I have a class with 4 distinct columns. div class="mainContent"> <div class="left-Col-1" *ngIf="data-1"> </div> <div class="left-Col-2" *ngIf="!data-1"> ...

Identifying activity on a handheld device

I am currently working on a website and I have noticed that it doesn't work as well on mobile devices as it does on desktop. There are performance issues that need to be addressed. I've seen other websites redirecting users to a different page wh ...

Securing routes in a Next.js 13 application for both client-side and server-side pages

After exploring various sources, I have noticed that there are different methods being used to protect pages in Next.js. Some developers utilize middleware.js to safeguard both client-side and server-side pages, while others opt for the useSession hook for ...

tips for dynamically highlighting search bar after choosing a different dropdown option - vuejs

I need to filter products in my application based on name and category. To achieve this, I have included a search text box and a dropdown select box. The dropdown select box offers two options: 1. Search products by name 2. Search products by category name ...

I ran into a problem while trying to install next.js

I am currently setting up Next.js for the first time on my Mac terminal using the command <a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="74170611150011591a110c00591504043445405a465a47">[email protected]</a>. Prior ...

Is there a way to convey a function existing on the Server Component to the Client Component?

Seeking assistance with NEXTJS 13 'app Dir' Is there a way to transfer a function from the Server Component to the Client Component? I have a Button as my Client component and it is wrapped by another Server Component. I want the Button to exec ...

Using Vue and vue-multiselect to create interactive options based on the selected language

I'm currently developing a Vue website with multilingual support. The chosen language is stored in a Vuex store and accessed through the computed property lang, like so: lang(){ return this.$store.state.lang } I use this lang property in v-if cond ...

Having trouble testing firebase messaging on my local server

I've encountered an issue while trying to retrieve a token from firebase/messaging for use in notifications. The error message "messaging/unsupported-browser" (FirebaseError: Messaging: This browser doesn't support the API's required to use ...

What are the steps to launching a node.js application on CyberPanel?

I have a node.js application developed and running on my server with cyberpanel installed. While I have found numerous examples of how to deploy a node application in cyberpanel, I am unsure about how to access it from the browser. Currently, my vHost con ...

Monitor a user's activity and restrict the use of multiple windows or tabs using a combination of PHP and

I am looking to create a system that restricts visitors to view only one webpage at a time, allowing only one browser window or tab to be open. To achieve this, I have utilized a session variable named "is_viewing". When set to true, access to additional ...

Tips for using the fetch() method to send an object to a dynamic API route in Next.js

I'm running into a problem when trying to send an object to my dynamic API route in Next.js. Everything works fine when sending a regular string, and I can update my MongoDB without any issues. However, when attempting to send an object, the request d ...

Tips for ensuring the child directive has finished rendering before proceeding?

I am faced with a scenario where one directive is dependent on another: <div style="border:2px solid black;height:150px;padding:10px"> <my-internal-directive></my-internal-directive> <my-internal-directive></my-interna ...

Navigating with useRouter().push() from the "next/navigation" package is not functioning as expected when used on a customized signIn page alongside next-auth

Upon logging in successfully on my custom signIn-Page using next-auth, I am facing an issue with redirecting back to the callbackUrl. The setup includes react 18.2.0, next 13.4.8-canary.2, and next-auth 4.22.1. The code for the signIn-Page (\src&bsol ...

Store the token securely in your browser's localStorage and set up interceptors

Struggling with saving the token in localStorage and pushing it in interceptors to send it with all requests. Currently, passing user data and token from Symfony controller to frontend, but facing roadblocks in saving the token in localStorage and settin ...

The scroll() function in jQuery does not bubble up

Recently, I encountered an issue with a Wordpress plugin that displays popups on scroll. The code I currently have is as follows: jQuery(window).scroll(function(){ //display popup }); The problem arises with a particular website that has specific CSS ...

Every checkbox has been selected based on the @input value

My component has an @Input that I want to use to create an input and checkbox. import { Component, EventEmitter, Input, OnInit, Output } from '@angular/core'; @Component({ selector: 'app-aside', templateUrl: './aside.component ...