-
-
Notifications
You must be signed in to change notification settings - Fork 26.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
CRA 4 fails to compile when css background-image ulr('url') not resolved #10022
Comments
This guide still works: https://create-react-app.dev/docs/adding-images-fonts-and-files You should not link to the public folder in your src or css. Create a static directory in your src folder and do like:
|
@pascalstr, Your solution works, but I have to move all the assets that do not need to be in the src folder, such as images, videos, fonts, and so on. Also, all of these will beside together in the media folder that CRA created by default and is not customized for production. |
@pascalstr Thanks that works for me! |
@saeed-rohani #9937 seems to be a similar issue, maybe close this in favour of #9973 |
@saeed-rohani The guide makes sense but how would you reference an image in an inline style to do something like this: style={{backgroundImage:"url(/img/example.png)"}} in this case static will not work and the use case being... style={{backgroundImage:"url(/img/example-"+var+".png)"}} Cheers |
I'm surprised this isn't a show stopper for more people. Any light on a work around or approach I'm not getting would be helpful. Cheers! |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
any progress on this? i just spent too many hours figuring why my app won't suddenly compile after upgrading react scripts |
I'm surprised that more people haven't realised that this is a major concern for SEO. Lets say that you have a image file within the src folder, and you're using it within your CSS file like this - .Profile { If this profile.png file is inside the https://{my-domain.com}/static/media/profile.{hash}.jpg This {hash} value changes with every build. Therefore, if you use this in a static website, and if your website is crawled by google bot, you may see 404's reported in the google search console the next time you deploy, because Google can take several weeks before indexing your site again. This is where an image in the |
Same error over here. In CRA 3.4 it just was worked fine. :( |
Hi, I am new in issue discussion |
Hey for quick fix you can use craco (https://github.com/gsoft-inc/craco/tree/master/packages/craco) install per instructions. In my case im using .cracorc file. Put this inside .cracorc: Save, when launched with changed package.json (see craco install instructions) with CRA 4.0 .scss properly resolves from public just like before |
Is there no better fix than using yet another package with yet another configuration file? Moving my assets into src doesn't work (and I don't like the idea anyway), whether I use url("/aze"), url("./aze") or url("aze"). I'm going to try downgrading now but this sucks. |
What changes are planned in this regard? |
I ran into this issue too. I was previously using something like: Inside of
Now all my static CSS files sit inside the |
This issue has been automatically marked as stale because it has not had any recent activity. It will be closed in 5 days if no further activity occurs. |
Closing in on almost 36 months since this issue was opened. I would be interested in creating a pull request to resolve this but am not sure where to start, any recommendations on how I could begin to get this fixed? |
I have a css file that is imported in my react app, it is something like:
styles.css
.flag { ... background-image: url("/img/flags.png") !important; }
It is imported in my react file -> import './styles.css';
In the previous version of CRA it works well, and when I build the app it was also okay, since I have the /img/flags.png in my 'public' directory.
After CRA 4 it fails to compile
Best regards
The text was updated successfully, but these errors were encountered: