Rails compiler error with fontawesome when deploy

2020-07-26 17:41发布

问题:

I got an error message when I try to push my Rails project to Heroku. I am using Fontawesome, it works prefectly in local environment but just won't push to Heroku.

Running: rake assets:precompile I, [2016-03-22T05:59:25.096354 #366] INFO -- : Writing /tmp/build_3e31f1bb8b828cb787890706e9ec589b/public/assets/FontAwesome-0d34da07e5cbcb4ff087b397966a9f9ffb4d6ed7c7060568565203c02f3fee11.otf I, [2016-03-22T05:59:25.099701 #366] INFO -- : Writing /tmp/build_3e31f1bb8b828cb787890706e9ec589b/public/assets/fontawesome-webfont-e511891d3e01b0b27aed51a219ced5119e2c3d0460465af8242e9bff4cb61b77.eot

rake aborted! Sass::SyntaxError: Invalid CSS after "...orm-group::not(": expected pseudo_expr, was ":first-child)" (sass):9108

/tmp/build_3e31f1bb8b828cb787890706e9ec589b/vendor/bundle/ruby/2.2.0/gems/sprockets-rails-3.0.4/lib/sprockets/rails/task.rb:67:in block (2 levels) in define' Tasks: TOP => assets:precompile (See full trace by running task with --trace) ! ! Precompiling assets failed. ! ! Push rejected, failed to compile Ruby app

Here is my gemfile:

source 'https://rubygems.org'

gem 'sprockets', '~> 3.0'
gem 'rails', '4.2.6'
gem 'pg', '~> 0.15'
gem 'sass-rails', '~> 5.0'
gem 'uglifier', '>= 1.3.0'
gem 'coffee-rails', '~> 4.1.0'
gem 'jquery-rails'
gem 'turbolinks'
gem 'jbuilder', '~> 2.0'
gem 'sdoc', '~> 0.4.0', group: :doc

group :development, :test do 
 gem 'byebug'
end

group :development do
  gem 'web-console', '~> 2.0'
  gem 'spring'
end

回答1:

Put this gem in your gem file:

gem 'font-awesome-sass', '~> 4.5.0'

Then import these in your application.scss

 @import "font-awesome-sprockets";
 @import "font-awesome";

Then bundle install the gem using console.

Then(important) use rake in console to clean and precompile your assets before push to Heroku

rake assets:clean
rake assets:precompile

Now your assets should be compile correctly when you push.



回答2:

might be easier to use: gem 'font_awesome5_rails'