Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

137
Views
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 answers
Answer question

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 Report

0

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

almost 4 years ago · Santiago Trujillo Report

0

i think you missing the file to ref use

import logo from '../../assets/logo.xxx
almost 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!