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

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

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 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!