error compiling assets with image-url tag
gleydsonst opened this issue · comments
I'm using the new cssbundling-rails gem. It's working perfect in dev, but in prod i'm getting this error when i'm trying to compile the assets:
following the doc: https://guides.rubyonrails.org/asset_pipeline.html#css-and-sass
footer {
background-image: image-url("ruby.png");
}
just url("ruby.png")
doesn't work, but it worked with the webpacker:
footer {
background-image: url("ruby.png");
}
RAILS_ENV=production bundle exec rake assets:precompile
/home/app/myapp/shared/bundle/ruby/3.0.0/gems/sassc-2.4.0/lib/sassc/engine.rb:43: [BUG] Segmentation fault at 0x0000000000000000
ruby 3.0.2p107 (2021-07-07 revision 0db68f0233) [x86_64-linux]
-- Control frame information -----------------------------------------------
c:0042 p:---- s:0308 e:000307 CFUNC :compile_data_context
c:0041 p:0314 s:0303 e:000302 METHOD /home/app/myapp/shared/bundle/ruby/3.0.0/gems/sassc-2.4.0/lib/sassc/engine.rb:43
c:0040 p:0044 s:0291 e:000290 METHOD /home/app/myapp/shared/bundle/ruby/3.0.0/gems/sassc-rails-2.1.2/lib/sassc/rails/compressor.rb:29
c:0039 p:0007 s:0285 e:000284 METHOD /home/app/myapp/shared/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/sass_compressor.rb:30
c:0038 p:0047 s:0280 e:000279 METHOD /home/app/myapp/shared/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:84
c:0037 p:0014 s:0272 e:000271 BLOCK /home/app/myapp/shared/bundle/ruby/3.0.0/gems/sprockets-4.0.2/lib/sprockets/processor_utils.rb:66 [FINISH]
c:0036 p:---- s:0267 e:000266 CFUNC :reverse_each
/home/app/.rbenv/versions/3.0.2/lib/ruby/3.0.0/set.rb:344:in `each'
/home/app/.rbenv/versions/3.0.2/lib/ruby/3.0.0/set.rb:344:in `each_key'
-- Machine register context ------------------------------------------------
RIP: 0x00007f56666db03c RBP: 0x00007f56678fca30 RSP: 0x00007f56678fca30
RAX: 0x0000000000000000 RBX: 0x00007f56581bde58 RCX: 0x0000000000000000
RDX: 0x0000000000000000 RDI: 0x0000000000000000 RSI: 0x00007f56678fca10
R8: 0x00005615af11de90 R9: 0x0000000000000006 R10: 0x00007f5666315446
R11: 0x00007f56666db02c R12: 0x0000000000000000 R13: 0x0000000000000001
R14: 0x00005615b0c4f8c8 R15: 0x00007f56678fdaac EFL: 0x0000000000010202
-- C level backtrace information -------------------------------------------
/home/app/.rbenv/versions/3.0.2/lib/libruby.so.3.0(rb_print_backtrace+0x11) [0x7f566bf23d83] vm_dump.c:758
/home/app/.rbenv/versions/3.0.2/lib/libruby.so.3.0(rb_vm_bugreport) vm_dump.c:998
/home/app/.rbenv/versions/3.0.2/lib/libruby.so.3.0(rb_bug_for_fatal_signal+0xf4) [0x7f566bd2ee04] error.c:786
/home/app/.rbenv/versions/3.0.2/lib/libruby.so.3.0(sigsegv+0x4d) [0x7f566be7ac5d] signal.c:960
/lib/x86_64-linux-gnu/libc.so.6(0x7f566baac210) [0x7f566baac210]
I have similar issue. RAILS_ENV=production bundle exec rake assets:precompile
always crash, there is no problem with development environment. After isolate scss file one by one, I realized that it crashed due to "asset-url" inside scss file.
@font-face {
font-family: 'Source Sans Pro';
src: asset-url('source-sans-pro-v14-latin-regular.eot'); --> this line causes crash
...
font-weight: normal;
font-style: normal;
}
I tried many ways that found by google such as
- Downgrade sprockets from "4.0" to "3.7.2"
- Add "env.export_concurrent = false" to initializers/assets.rb
- Play around with Rails.application.config.assets.precompile += ....
- ...
None of them work. Finally, I could fix it by below hack
. I manually handle get
method to asset files (depending on file name, then I redirect to corresponding asset file)
- Change from "asset-url()" to "url()"
- Update config/routes.rb by adding below code
if Rails.env.production?
f_redirector = lambda { |params, _req|
_path = params[:name] + _req.path.gsub(/.*\./, '.')
ApplicationController.helpers.asset_path(_path)
}
constraint = ->(request) {
request.path.ends_with?('.eot') ||
request.path.ends_with?('.woff') ||
request.path.ends_with?('.ttf') ||
request.path.ends_with?('.svg') ||
request.path.ends_with?('.png')
}
get '/assets/*name', to: redirect(f_redirector), constraints: constraint
end
This is a dirty hack, but at least my production could work temporary work for now.