扶手:找出哪些文件会导致萨斯:: SyntaxError异常?(Rails: finding out

2019-09-28 14:53发布

当我运行:

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'
....

我怎样才能找出导致该异常的文件吗? 是否有青菜护栏的选项来调试这个问题?

注:此应用程序的CSS / JavaScript是在开发模式下工作。 此异常仅在生产预编译的资产或运行RSpec的功能测试时发生的时候。

注2: 启用config.css_compressor此问题时才会发生。 如果我禁用它,资产预编译没有问题。

Answer 1:

我有同样的问题。 输出只告诉你它没有在哪一行,而不是实际的文件名。 非常简单快速和肮脏的解决办法是打开文件引发错误“/Users/fernando/.rvm/gems/ruby-2.3.0/gems/sass-3.4.21/lib/sass/scss/parser.rb”和添加一个看跌期权来初始化:

  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),并添加使用实例变量错误前行卖出期权声明:

 line 1178: puts @filename


Answer 2:

我不能找到一种方法,让Rails的给我更多的信息,哪些文件是造成问题。

因此,解决办法是写一个脚本,删除一个CSS文件,运行资产:预编译和检查返回代码。 我跑这个脚本循环对所有的CSS / SCSS文件,直到资产:预编译终于奏效。 这是造成这一问题的第三方的CSS文件。

我不得不手动检查文件,直到我发现了//这是无效的CSS一些意见。

除去这些意见后,耙资产:预编译的所有文件的工作。



文章来源: Rails: finding out which file causes Sass::SyntaxError exception?