React path to public folder in css background image


I am using Create-React-App and I want to add background image for my header section and I am doing this in that way:

background-image: url('~/Screenshot_11.png');

After this I’m getting this error:

Module not found: You attempted to import
../../../../../../../Screenshot_11.png which falls outside of the
project src/ directory. Relative imports outside of src/ are not

I’ve set up homepage in package.json

"homepage": "http://localhost:3000",

In my older projects that works but today I cannot import this correctly.


They have changed that but I don’t know why. Working path:

background-image: url('/Screenshot_11.png');

EDIT 2021

For people who think that it doesn’t work:

Answered By – Freestyle09

Answer Checked By – Willingham (AngularFixing Volunteer)

Leave a Reply

Your email address will not be published.