当我跑步时:
rake assets:precompile RAILS_ENV=production --trace
我得到以下异常:
rake aborted!
Sass::SyntaxError: Invalid CSS after " */": expected "}", was ""
(sass):19419
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/scss/parser.rb:1179:in `expected'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/scss/parser.rb:1115:in `expected'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/scss/parser.rb:1110:in `tok!'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/scss/parser.rb:656:in `block'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/scss/parser.rb:647:in `ruleset'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/scss/parser.rb:673:in `block_child'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/scss/parser.rb:666:in `block_contents'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/scss/parser.rb:123:in `stylesheet'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/scss/parser.rb:39:in `parse'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/engine.rb:403:in `_to_tree'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/engine.rb:278:in `render'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sprockets-3.5.2/lib/sprockets/sass_compressor.rb:48:in `call'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sprockets-3.5.2/lib/sprockets/sass_compressor.rb:28:in `call'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:75:in `call_processor'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sprockets-3.5.2/lib/sprockets/processor_utils.rb:56:in `call_processors'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:134:in `load_from_unloaded'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:60:in `block in load'
/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sprockets-3.5.2/lib/sprockets/loader.rb:318:in `fetch_asset_from_dependency_cache'
....
如何查找导致此异常的文件? sass-rails中是否有选项来调试此问题?
注意:此应用程序的CSS / Javascript正在开发模式下运行。只有在生产中或运行rspec功能测试时预编译资产时才会发生此异常。
注意2:此问题仅在启用 config.css_compressor 时发生。如果我禁用它,资产将被预编译而不会出现问题。
答案 0 :(得分:2)
我遇到了完全相同的问题。输出仅告诉您它失败的行,而不是实际的文件名。真的很简单快速&脏修复是打开文件抛出错误“/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/scss/parser.rb”并添加一个put初始化器:
def initialize(str, filename, importer, line = 1, offset = 1)
puts filename # ADD THIS LINE.
@template = str
@filename = filename
@importer = importer
@line = line
@offset = offset
@strs = []
@expected = nil
@throw_error = false
end
这会产生大量的输出但是当它失败时你会得到文件名。或者,由于文件名变量被放入实例变量@filename,您可以从回溯中的第一行(在您的情况下为1179)中获取行号,并使用实例变量将puts语句添加到错误之前的行:
line 1178: puts @filename
答案 1 :(得分:0)
我找不到让Rails为我提供有关哪个文件导致问题的更多信息的方法。
所以解决方案是编写一个删除CSS文件的脚本,运行assets:precompile并检查返回代码。我在所有css / scss文件上运行此脚本循环,直到资产:预编译最终工作。这是导致该问题的第三方CSS文件。
我必须手动检查文件,直到找到一些对CSS无效的评论。
删除这些评论后,rake资产:预编译可以处理所有文件。