I can't set a backgorund image in tailwind.config.js because of faild to compile. #3113
-
I wrote the following file using this as the reference about customizing backgroud image. module.exports = {
purge: ["./src/**/*.tsx"],
darkMode: false, // or 'media' or 'class'
theme: {
extend: {
backgroundImage: theme => ({
'hero-img': "url('/img/hero.webp')"
})
},
},
variants: {
extend: {},
},
plugins: [],
} But, I got compile error like this.
My file tree is:
and @tailwind base;
@tailwind components;
@tailwind utilities; I don't use any framwork like Next.js. I created this project with this command.
What should I do to success my compiling? |
Beta Was this translation helpful? Give feedback.
Replies: 8 comments 3 replies
-
Hey! Doing some research to help you debug, I have learned that while CRA tells you to put your images in I created a new app from scratch with your installation steps, and was able to reproduce the same error. Moving my image from 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 sits in comparison with your page in the theme: {
extend: {
backgroundImage: theme => ({
- 'hero-img': "url('/img/hero.webp')"
+ 'hero-img': "url('./img/hero.webp')"
})
},
}, You shouldn't have to do that, but if it still doesn't work after moving your image in Hope it helps 👍 |
Beta Was this translation helpful? Give feedback.
-
I am having this same issue as well, 2 years later. I tried the suggested solution, however, tailwind is still recognizing Ideally, I would like to configure an image directory in my |
Beta Was this translation helpful? Give feedback.
-
I had the same issue and fixed it just by putting /public in front of my /img like this : 'test-img': "url('/public/img/test.jpg')", |
Beta Was this translation helpful? Give feedback.
-
Ah, thanks for adding this! Yeah, I'm putting |
Beta Was this translation helpful? Give feedback.
-
Hi there! It's doesn't works yet |
Beta Was this translation helpful? Give feedback.
-
Hi, there! I'm trying to use the extend backgroundImage from tailwindcss, and works good on my develop environment, but, it's doesn't works on published application. |
Beta Was this translation helpful? Give feedback.
-
Hi, has anyone found a solution to this? Do we know if our images need to be inside the public or src folder and how we're to go about writing out the relative path? |
Beta Was this translation helpful? Give feedback.
-
Just spent 2h trying to solve it, unfortuanlly nothing helped. And if i type the correct path of the image, the application crashes and i have to restart with npm run dev, using Next. What i could do was this on my page.tsx file import img from '../../../public/images/fundo1.jpg' |
Beta Was this translation helpful? Give feedback.
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 yoursrc
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
tosrc/images/my-image.jpg
made the error go away 👍If the following image path still doesn't work for you after that change...
... then try to use a relative path to where the image si…