skip to Main Content

I’m trying to import images in react, i’ve searched tons of answer and videos but just cant seem to get mine working.

Here’s my directory:
enter image description here

Here’s my code

import React from 'react';
import './header.css'
import people from '../assets/people.png';

and the error im getting is

ERROR in ./src/containers/header/header.jsx 6:0-42
Module not found: Error: Can't resolve '../assets/people.png' in 'C:Usersojadigpt3_jsmsrccontainersheader'

2

Answers


  1. You’re importing one level too shallow.

    It should be:

    import people from '../../assets/people.png';
    
    Login or Signup to reply.
  2. What you need in your import is two levels, you’re imported one ../assets

    import '../../assets/people.png';
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search