error precompiling assets when moving to production

▼魔方 西西 提交于 2019-12-09 14:03:50

问题


I am trying to move my project to production,
trying to

RAILS_ENV=production bundle exec rake assets:precompile

gives me an error, without specifying in which file it is.

rake aborted!
Sass::SyntaxError: Invalid CSS after "}": expected selector or at-rule, was "}"
(sass):89
/Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:1207:in `expected'
/Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:1137:in `expected'
/Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/scss/parser.rb:42:in `parse'
/Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/engine.rb:406:in `_to_tree'
/Users/mac/.rvm/gems/ruby-2.2.3/gems/sass-3.4.23/lib/sass/engine.rb:281:in `render'
/Users/mac/.rvm/gems/ruby-2.2.3/gems/sprockets-3.7.1/lib/sprockets/sass_compressor.rb:48:in `call'
/Users/mac/.rvm/gems/ruby-2.2.3/gems/sprockets-3.7.1/lib/sprockets/sass_compressor.rb:28:in `call'
/Users/mac/.rvm/gems/ruby-2.2.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:75:in `call_processor'
/Users/mac/.rvm/gems/ruby-2.2.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/Users/mac/.rvm/gems/ruby-2.2.3/gems/sprockets-3.7.1/lib/sprockets/processor_utils.rb:56:in `reverse_each'

how do I findout in which file that error occurs? even with --trace it doesnt tell me.


回答1:


Found this issue while researching: https://github.com/rails/sass-rails/issues/368. Apparently, you'll have to check each file to find out which one is failing to compile.

But you can create a rake task to help with the process:

Just add the following code to a lib/tasks/assets.rake file

namespace :assets do

  desc "Find Sass::SyntaxError files..."
  task find_scss_with_error: :environment do
    files = Dir.glob( Rails.root.join("app", "assets", "stylesheets", "**/*")).grep(/.*\.[css|scss]/)
    files.each do |file|
        print "Trying to compile #{file}..."
        template = File.read(file)
        sass_engine = Sass::Engine.new(template)
        begin
            sass_engine.render
            print "[OK]"
        rescue
            print "[ERROR]"
        end
        puts
    end
  end

end

and run

rake assets:find_scss_with_error

Results:

Trying to compile /data/ruby/scss-comments-failure/app/assets/stylesheets/example.css...[ERROR]
Trying to compile /data/ruby/scss-comments-failure/app/assets/stylesheets/application.css...[OK]

Some notes:

  • It'll check for *.css and *.scss files, including subdirectories.
  • The script will not output compression to file. It's just a in-memory test.


来源:https://stackoverflow.com/questions/41649496/error-precompiling-assets-when-moving-to-production

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!