Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Background Image not showing on build React

I have a component structured like this:

<div style={{ backgroundImage: `url(${require("src/assets/images/loginImage.png")})`, backgroundSize: 'cover' }}>

my folder structure is the following : Folder structure

Now, the image background shows up correctly when I run locally. But when I build and deploy online, the image doesn't show up.

The funny thing is that the icons do get loaded with no problems, and i refer to them in the same way

Does any of you have a clue on why this is happening?

Thanks

like image 973
Jorgio Avatar asked Oct 26 '25 08:10

Jorgio


1 Answers

you can try this

import loginImage from "src/assets/images/loginImage.png";

<div style={{ backgroundImage: `url(${loginImage})`,backgroundSize: 'cover' }}>
like image 195
ikmo Avatar answered Oct 28 '25 21:10

ikmo



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!