Back

rails - rake assets:precompile 遇到错误:SassC::SyntaxError: Error: Invalid CSS after "}":

发布时间: 2022-09-01 04:13:00

refer to: https://stackoverflow.com/questions/54267203/sasscsyntaxerror-error-invalid-css-after/73564234#73564234

问题很难排查。

不过不要紧, 直接修改gem file, 让问题暴露出来即可。

见上面的stack over flow

I met the same problem.

to solve it, the key is find what is the content of "stdin", so we have to modify your local gem file and add debug outputs:

# edit (/home/siwei/.asdf/installs/ruby/3.0.4/lib/ruby/gems/3.0.0/gems/sassc-rails-2.1.2/lib/sassc/rails/compressor.rb)

   def call(*args)
     input = if defined?(data)
       data # sprockets 2.x
     else
       args[0][:data] #sprockets 3.x
     end
     # add these debug lines of code 
     puts "=== input is: "
     File.write('/tmp/temp_scss', input)
     puts "=== input end "

     SassC::Engine.new(
       input,
       {
         style: :compressed
       }
     ).render
   end


then run command:

RAILS_ENV=production bundle exec rails assets:precompile

then you will meet error, no worry, check out the file /tmp/temp_scss, find the "line 17881 of stdin", you will find the syntax error.

e.g. my error looks like:

enter image description here

Back