Coming soon - Get a detailed view of why an account is flagged as spam!
view details

This post has been de-listed

It is no longer included in search results and normal feeds (front page, hot posts, subreddit posts, etc). It remains visible only via the author's post history.

1
TypeScript+ React + Vite [plugin:vite:import-analysis] Failed to resolve import "./assets/heropic.png" from "src\components\Hero.tsx". Does the file exist?
Post Flair (click to view more posts with a particular flair)
Post Body

New to react, typescript. I'm trying to create a "Hero" Section for a site and want to render this pick in the background.

I've been stuck trying to import a png file from my assets folder to my Hero.tsx file in my components folder. Here's how tthe code looks:

(Hero.tsx in components folder)

import heropic from "./assets/heropic.png";
interface HeroProps {
children: React.ReactNode;
}
const Hero = (props: HeroProps) => {
return (
<section>
<img src={heropic} />
{props.children}
</section>

(App.tsx)

//import Header from "./components/Header";
import { Navbar } from "./components/Navbar";
import { Routes, Route } from "react-router-dom";
import { Container } from "react-bootstrap";
import { Home } from "./pages/Home";
import { About } from "./pages/About";
import { GetInvolved } from "./pages/GetInvolved";
import { Latest } from "./pages/Latest";
import { ContactUs } from "./pages/ContactUs";
import Hero from "./components/Hero";
function App() {
return (
<>
<Navbar />
<Container>
<Routes>
<Route path="/" element={<Home />} />
<Route path="/about" element={<About />} />
<Route path="/GetInvolved" element={<GetInvolved />} />
<Route path="/Latest" element={<Latest />} />
<Route path="/GetInvolved" element={<GetInvolved />} />
<Route path="/Contact" element={<ContactUs />} />
</Routes>
</Container>
<Hero>I'm Hero</Hero>
</>
  );
}
export default App;
I created a .d.ts file and a folder for it: and have imported react-svg and png

declare module "*.png" {
const value: any;
export default value;

// alt syntax: export = value //
  }

I get this error, 2nd pic is a view of most of my files.

Been stuck for a while, help would be appreciated. Thanks

Error message

Files

Author
Account Strength
60%
Account Age
2 years
Verified Email
Yes
Verified Flair
No
Total Karma
29
Link Karma
13
Comment Karma
16
Profile updated: 4 days ago
Posts updated: 1 week ago

Subreddit

Post Details

We try to extract some basic information from the post title. This is not always successful or accurate, please use your best judgement and compare these values to the post title and body for confirmation.
Posted
10 months ago