Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

217
Vistas
JS - how to importe correctly image from public folder

I have an image in the public folder called logo.png

when I try to import it in my index.js file (src/view/index.js) :

import logo from "public/logo.png";

I always get this error :

Module not found: You attempted to import /public/logo.png which falls outside of the project src/ directory. Relative imports outside of src/ are not supported.
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you are using an <img> element to display the image, it will have a src attribute. In that case, you can use the image url for the soruce. It looks like this:

const logo = `${process.env.PUBLIC_URL}/logo.png`;

Then to render it, you would have something like this:

<img
    alt='my-logo'
    src={logo}
/>
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda