Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

227
Visualizações
Can't find images paths from a local data array

Summary

Hey there! i’m working on a small project about a restaurant menu app which so i’m building this in vanilla JS using webpack as bundler.

Issue

the problem that i have is that when i’m using the data from a local array in my project can’t find the images path and i really don’t know why is happen this. project structure

enter image description here

How i’m using the data from the array:

import menu from '../data/data';

const Main = () => {
  const view = `
    <div class="menu-items">
      ${menu.map(menuItem => `
        <article class="menu-item">
          <img src=${menuItem.img} alt=${menuItem.title} class="photo" />
          <div class="item-info">
            <header>
              <h4>${menuItem.title}</h4>
              <h4 class="price">$${menuItem.price}</h4>
            </header>
            <p class="item-text">
              ${menuItem.desc}
            </p>
          </div>
        </article>
      `).join('')}
    </div>
  `;
  return view;
};

export default Main;

The error message appearing in my console:

enter image description here

My hunches are: maybe could be that i need an image webpack loader but also i think that is a problem with how i'm using or writing the images path, so if someone knows how i can solve this, pleas i hope you can help me.

Also here i left the project repo if is necessary for someone: https://github.com/armandopbringas/menu-app

about 4 years ago · Juan Pablo Isaza
3 Respostas
Responde à pergunta

0

I gave a quick look into your project on GIT. It seems like the "public" directory is the one that should contain the images.

That's the default directory that the server is getting the files.

Right now the images directory is on "src" directory.

When the browser requests an image on "http://localhost:8080/images/item-1.jpg" the server will look for it on "your-root-dir/public/images/item-1.jpg"

about 4 years ago · Juan Pablo Isaza Relatório

0

Just put yout image folder in 'public' directory, as suggested above, and it will work.

about 4 years ago · Juan Pablo Isaza Relatório

0

  1. Move the images folder to the public folder.
  2. Change the img link in the data menu array - /images/item-1.jpeg

enter image description here

enter image description here

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda