A
A
asdasdqwe2022-02-04 10:40:35
React
asdasdqwe, 2022-02-04 10:40:35

Unable to load image in react?

Is this a problem with react or with webpack

src
--imgs
------bg.jpg
--style.css

style.css

body {
  background-image: url('./imsg/bg.jpg');   // Текущая папка/imgs/bg.jpb
}


But it says file not found

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Smirator, 2022-02-04
@asdasdqwe

It's likely that images need to be required so that Webpack can process them.
An example with HTML, but in terms of styles everything should be similar
Something like this: - not ok. - OK. So Webpack should be able to process and replace the original img.
<img src={"/images/resto.png"} />
<img src={require('/images/image-name.png')} />

A
Arslan Abaev, 2022-02-05
@ADDtvb

Hello, try to write /imsg/bg.jpg
without a dot at the beginning, it's strange, but, in my opinion, it works in css
. Also, I noticed that in the description you wrote that your folder is called "imgs" and in the path you wrote "imsg".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question