J
J
Jusss2017-02-02 11:33:08
JavaScript
Jusss, 2017-02-02 11:33:08

Images not showing on localhost (React) How to fix?

Good afternoon, the problem is that the images do not open, even if it is in the same folder as the component itself ... In fact, the images are in a completely different folder, but due to the fact that they do not want to open, I started Throw them into the same folder, but it still does not open. I tried a bunch of paths, other formats ...
for example, I set:

technologies: [
    {
      name: 'development',
      path: 'dev.png',
      link: '/'
    }
...

{
      this.state.technologies.map(function (res, i) {
        return <a key={i} href={res.link} >
          <img src={res.path} />
          <span class="name">{res.name}</span>
        </a>
      })
    }

In console:
Failed to load resource: the server responded with a status of 404 (Not Found) left.png
Failed to load resource: the server responded with a status of 404 (Not Found) settings.png
Failed to load resource: the server responded with a status of 404 (Not Found) process.png
Failed to load resource: the server responded with a status of 404 (Not Found) coding.png
Failed to load resource: the server responded with a status of 404 (Not Found)
> I use npm, webpack.
If you set, for example, a background from a css file, then the image is displayed, but if you set some img src from the component, then it is not displayed. This is some nonsense. Maybe something is wrong in the webpack config, but everything seems to be normal, and should not affect at all

Answer the question

In order to leave comments, you need to log in

4 answer(s)
K
kruvv, 2020-11-30
@kruvv

In the file where the img tag is located, import your image, and then refer to this import in src.

V
Victor Oberemko, 2017-02-02
@Swistik

Jusss , but what does it write in the path for src, if you look at the usual DOM?

S
Shane Matte, 2017-02-07
@mattedev

Webpack will read from the public folder that you specified, when adding files, always write ./

A
AnnaBam, 2020-01-30
@AnnaBam

put the images in the public folder and refer to them simply by the file name img src= " .... "

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question