Skip to content
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

Fonts not loading with dart sass in Rails 7 #222

Open
michaelrevans opened this issue Oct 28, 2023 · 10 comments
Open

Fonts not loading with dart sass in Rails 7 #222

michaelrevans opened this issue Oct 28, 2023 · 10 comments

Comments

@michaelrevans
Copy link

I have a Rails project that uses dartsass for SASS to CSS compilation.

Having followed through the installation instructions, the fonts are missing and it's giving a simple routing error in the rails server logs:

ActionController::RoutingError (No route matches [GET] "/webfonts/fa-solid-900.ttf"):

and the same for the woff2 file.

Unsurprisingly, when trying to use the fonts in a view (using ERB), it's not showing any content and the browser console displays the a similar 404 error:

GET http://localhost:3000/webfonts/fa-brands-400.ttf net::ERR_ABORTED 404 (Not Found)
@Ozkee
Copy link

Ozkee commented Dec 4, 2023

Did you find the solution?
Here it is, in your application.scss:
@use 'font-awesome' with ($fa-font-path: 'font-awesome');

@joshuacronemeyer
Copy link

@Ozkee thanks for this. nothing worked until i found this issue and your comment.

@joshuacronemeyer
Copy link

joshuacronemeyer commented Dec 29, 2023

Actually @Ozkee's suggestion got the icons working for me, for example when i do

<%= icon('fa-brands', 'font-awesome')%>

everything works, but I too am seeing some 404s in the console. Not causing me issues but wondering if i'm still missing something.

Started GET "/webfonts/fa-solid-900.woff2" for ::1 at 2023-12-29 09:40:41 -0600

ActionController::RoutingError (No route matches [GET] "/webfonts/fa-solid-900.woff2"):

Started GET "/webfonts/fa-solid-900.ttf" for ::1 at 2023-12-29 09:40:41 -0600

ActionController::RoutingError (No route matches [GET] "/webfonts/fa-solid-900.ttf"):

Started GET "/webfonts/fa-regular-400.woff2" for ::1 at 2023-12-29 09:40:41 -0600

ActionController::RoutingError (No route matches [GET] "/webfonts/fa-regular-400.woff2"):

Started GET "/webfonts/fa-regular-400.ttf" for ::1 at 2023-12-29 09:40:41 -0600

ActionController::RoutingError (No route matches [GET] "/webfonts/fa-regular-400.ttf"):

i checked and using an fa-regular icon is working.

@fschiefelbein
Copy link

fschiefelbein commented Feb 27, 2024

@joshuacronemeyer, I have changed _variables.scss from
$fa-font-path : "../webfonts" !default;
to
$fa-font-path : "assets/font-awesome/webfonts" !default;

and fixed all routing errors. Just check your path matches.
With this change you don't need to add the @use statement to your application.scss

@joshuacronemeyer
Copy link

ok interesting @fschiefelbein so are you rebuilding a gem from your own fork or are you overriding this somehow in your app. I see the file and line you've changed, just wondering what's the best way to incorporate it. I wonder if you made a PR for this if they would merge it

@fschiefelbein
Copy link

I came across this issue without using the gem, I am just using dartsass-rails and hosting fontawesome files. I changed my _varialble.scss file in my app. I didn't make a PR for this.

@dima4p
Copy link

dima4p commented Jun 14, 2024

This patch should help

@YuriDSS
Copy link

YuriDSS commented Aug 4, 2024

Did you find the solution? Here it is, in your application.scss: @use 'font-awesome' with ($fa-font-path: 'font-awesome');

Thanks @Ozkee , the icons only started working after i added the configuration exactly as you indicated. Thanks you so much!

@joshuacronemeyer
Copy link

joshuacronemeyer commented Aug 30, 2024

@dima4p when i tried that patch it didn't do anything for me

what i tried was changing my Gemfile like this

-gem "font-awesome-sass", "~> 6.5"
+gem "font-awesome-sass", github: 'dima4p/font-awesome-sass', ref: 'bed06b0e9c62ec7e9523879d2012d43ec14afa75'

and then rebuilding my sass. I was still seeing the 404s. To clarify the icons are working for me, but wanted to get rid of the 404s

@dima4p
Copy link

dima4p commented Sep 1, 2024

@dima4p when i tried that patch it didn't do anything for me

what i tried was changing my Gemfile like this

-gem "font-awesome-sass", "~> 6.5"
+gem "font-awesome-sass", github: 'dima4p/font-awesome-sass', ref: 'bed06b0e9c62ec7e9523879d2012d43ec14afa75'

and then rebuilding my sass. I was still seeing the 404s. To clarify the icons are working for me, but wanted to get rid of the 404s

What version of Rails did you use? I used 7.2.
Additionally it is not clear, what is the point in the code, that results in 404.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants