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

138
Visualizações
module not found in react js when using a path of image

i just started react js but having trouble in importing a path of image to the webpage. I have a folder named assets and it have images, i want to use those images in my project but when giving it as a input in the code it shows: "ERROR in ./src/containers/products/Products.jsx 7:0-33 Module not found: Error: Can't resolve '../../assets/'"

Here is the code for the following

import React from 'react';
import './products.css';
import {Prodfeat} from '../../components'
import logo from '../../assets/';

const Products = () => {
    return (
      <div className='gpt3__products' id='products'>
        <div className='gpt3__products-heading'>
          <h1>We have something for everyone!</h1>
        </div>
        <div>
          <Prodfeat title='product 1' text='description of product1' productimg={`${logo}blog01.png`}/>
          <Prodfeat title='product 2' text='description of product2' productimg={`${logo}blog02.png`}/>
          <Prodfeat title='product 3' text='description of product3' productimg={`${logo}blog03.png`}/>
        </div>

      </div>
    )
  }

here is the code for the prodfeat component:

import React from 'react';
import './prodfeat.css';

const Prodfeat = ({title, text, productimg}) => {
  return (
    <div className='gpt3__prodfeat' >
        <div className='gpt3__prodfeat-desc'>
            <div className='gpt3__prodfeat-heading'>
                <h2>{title}</h2>
            </div>
            <div className='gpt3__prodfeat-text'>
                <p>{text}</p>
            </div>
        </div>
        <img src={productimg} alt={title}/>
    </div>
  )
}

i want to use the {logo} as a reference variable and point toward the photo so that i dont have to write the path again and again but it is not accepting it as the path but just a string. Please if you got any suggestions guide me in this problem. Thank you

almost 4 years ago · Santiago Trujillo
3 Respostas
Responde à pergunta

0

you are using an absolute path when setting the src prop on the img element. you cannot achieve this when your images are located in the src folder . your images should be located in the public directory . then you don't need to import them just use the absolute path .

In your case : instead of : import logo from '../../assets/';

put your images inside public folder and store the path to a variable like this :

const logo = '<the path here >'

and access them :

<Prodfeat title='product 1' text='description of product1' productimg={`${logo}blog01.png`}/>

I made a codesandbox to show you exactly how it works !

almost 4 years ago · Santiago Trujillo Relatório

0

use this import import logo from '../../assets/logo.<file_format>';

almost 4 years ago · Santiago Trujillo Relatório

0

i think you missing the file to ref use

import logo from '../../assets/logo.xxx
almost 4 years ago · Santiago Trujillo 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