skip to Main Content

I’m currently learning React and I’m having a problem, when I launch my app it says that it can’t find modules at the location I gave. I believe I have written the correct path but it would seem that’s not the case. I’ve looked around and tried all the different options I’ve found but they haven’t worked so far.
Is there something I’m not getting ?
This is the error I’m getting
This is the organization of my files and folders
This is the code I have in my Home.jsx file

I tried changing the way I wrote the path to find the files and elements I need but to no avail.

./
../
src/components/

I always get the same error…

2

Answers


  1. Import it like this.

    import Banner from "../../components/banner/Banner"
    
    Login or Signup to reply.
  2. See whenever you want to import some component from different file, following thing you need to keep in mind.

    1. if the file is present in same folder, you can simply do
      "./file" where "./" represents that, file is going to be picked from
      same location.

    2. if the file is present one level outside current folder.
      "../file" where "../" represent we are going a level outside the
      current folder, keep in mind their is no space present between dots or the
      slash
      "../".

    3. if you have to access some component from file from inside folder of current
      location, we simply have to give folder name example, "./FolderLevel1/file".

      Taking your case we will be using "../../components/banner/Banner" since we
      have to go two level up and then have to import some component.

    Just remember there has to be no space between path dots or slashes.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search