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
Import it like this.
See whenever you want to import some component from different file, following thing you need to keep in mind.
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.
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 "../".
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.