I’m a beginner in React, and I feel like im overlooking something obvious here within this error:
"[vite] Internal server error: Failed to resolve import ‘/components/navbar’ from ‘src/App.jsx’. Does the file exist?"
I’ve used a similar project structure in previous projects without any issues. My project structure is as follows:(https://phpout.com/wp-content/uploads/2023/12/WwJd8.png)
Ive tried:
- import { Navbar } from "./components/navbar";
- import { Navbar } from "/components/navbar";
- import { Navbar } from "/components/navbar/Navbar";
Ive also tried moving the components folder out of the src folder.
I have attached screenshot of my workspace
Thank you
2
Answers
Your almost there the correct file path should be ./components/nabar/Navbar
You have made a mistake in addressing. If you have a problem in addressing, just open the file you want to import and do not close it, and mention its name where you want to use it and you will receive the address ready. In this file, the name is enough. Replace
/components/navbar/Navbar >>>> ./components/navbar/Navbar