Skip to content

I can't set a backgorund image in tailwind.config.js because of faild to compile. #3113

Answered by simonswiss
OldBigBuddha asked this question in Help
Discussion options

You must be logged in to vote

Hey!

Doing some research to help you debug, I have learned that while CRA tells you to put your images in public, when you want to reference them in your CSS (for background images), you need to actually have the image in your src folder instead 🙃

I created a new app from scratch with your installation steps, and was able to reproduce the same error.

Moving my image from public/images/my-image.jpg to src/images/my-image.jpg made the error go away 👍

If the following image path still doesn't work for you after that change...

theme: {
  extend: {
    backgroundImage: theme => ({
      'hero-img': "url('/img/hero.webp')"
    })
  },
},

... then try to use a relative path to where the image si…

Replies: 8 comments 3 replies

Comment options

You must be logged in to vote
2 replies
@OldBigBuddha
Comment options

@stardvst
Comment options

Answer selected by OldBigBuddha
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
1 reply
@JHunnicutt
Comment options

Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
10 participants