Vite: [plugin:vite:import-analysis] Failed to resolve import “../assets/sample” from “src/components/Navbar/Navbar.jsx”
”’
import { assets } from “../assets/sample”;
”’
However, when I run the development server, I receive the following error:
[plugin:vite:import-analysis] Failed to resolve import “../assets/sample” from “src/components/Navbar/Navbar.jsx”. Does the file exist?
The file structure is as follows:
src/
├── assets/
│ ├── sample.js
│ └── logo.png
├── components/
│ └── Navbar/
│ └── Navbar.jsx
In sample.js, I’m importing images and exporting them as an object:
”’
import logo from ‘./logo.png’;
export const assets = {
logo,
// other assets…
};
”’
My questions:
Why is Vite unable to resolve the import from sample.js?
Why does the assets object have the type any in my IDE?
How can I correctly import and use images in this setup?
Despite the file existing and the paths seeming correct, Vite throws the import analysis error.
Additionally, when I hover over assets in my IDE, it shows the type as any.
I’ve tried restarting the development server and checking the file paths, but the issue persists.