0

I'm trying to import a File. When I use the Relative Path I get an error. But when I use the full path. There is no problem. No idea why and it's bugging me a lot.

So when I use:

import SearchBar from './components/SearchBar/SearchBar.js';

I get:

Module not found: Can't resolve './components/SearchBar/SearchBar.js' 

But when I use the Full Path:

import SearchBar from /Users/xxx/Proyects/DevProyect/src/components/SearchBar/SearchBar.js

It runs ok.

Rahul Kumar
  • 362
  • 1
  • 7

1 Answers1

0

It depends on where you're making the import from.

In this case ./ is the current folder you're working on

That being said, if the file you're making import from is inside src folder then you can use

import SearchBar from './components/SearchBar/SearchBar.js';

and if the file you're making import from is inside components folder for example then you can use

import SearchBar from './SearchBar/SearchBar.js';

since both SearchBar folder and the file you're working on are in the same folder/directory.

Solar
  • 870
  • 9
  • 18
  • Thx for the answer. I looked all the files all over again. I had a repeated DevFolder in my user location. So when I was using the . to state my current folder I wasn't going to the folder I needed. I spent like 5 hours looking at the code and the problems was in folder all along. – Juan Pablo Rojas Jul 15 '20 at 14:55
  • Glad I could help – Solar Jul 15 '20 at 17:41