FabricioG
FabricioG

Reputation: 3310

Gatsby static path not resolving

The Gatsby documentation says that I can put an img file in the assets folder and I would be able to call it like so: url(someimage.png)

Following this I have the following. static/images/ here I have the image files.
Then in a css file I have this call to a url image.

.ui-accordion .ui-state-default {
    background: url(images/bg_widget_header.png) no-repeat 0 0;
}

I can verify that this image is here: images/bg_widget_header.png

I get the following error: error Generating development JavaScript bundle failed

Can't resolve './images/bg_widget_header.png' in '/Users/ohms/Code/eagle-eye-site/src/styles'

What am I missing or doing wrong?

Upvotes: 1

Views: 595

Answers (1)

Ferran Buireu
Ferran Buireu

Reputation: 29320

Yes, you can use an asset image to use it as a background. You may need to find the correct path using relativity, something like

background: url("../images/bg_widget_header.png") no-repeat 0 0;

In addition, you don't need to store that image in the /static folder since the image will be used and it's internal of the project, you can store it wherever you want and keep finding the path using relative paths (../../).

Upvotes: 1

Related Questions