Skip to content

Loading…

Compass cannot be found in production environment #25

Closed
manuelmeurer opened this Issue · 9 comments

4 participants

@manuelmeurer

I am trying to compile some assets during runtime using the following code:

Sprockets::StaticCompiler.new(
  Rails.application.assets,
  File.join(Rails.public_path, Rails.application.config.assets.prefix),
  Array("my_asset.css"),
  :digest   => false,
  :manifest => false
).compile

my_asset.css.scss:

@import "compass/typography/text/replacement";
.something { @include replace-text-with-dimensions("my_image.png"); }

It works great in development, but in production I get an error:

Sass::SyntaxError: File to import not found or unreadable: compass/typography/text/replacement.
Load path: /home/rails/myapp/releases/20120313170102
    from /home/rails/myapp/releases/20120313170102/app/assets/stylesheets/my_asset.css.scss:1

My first reaction was to require 'compass' before calling Sprockets::StaticCompiler.new but that lead to

NameError: uninitialized constant Sass::Util
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/haml-3.1.4/lib/sass/plugin.rb:7:in `<top (required)>'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/haml-3.1.4/lib/sass/rails3_shim.rb:15:in `block in <top (required)>'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `instance_eval'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:36:in `execute_hook'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/activesupport-3.2.2/lib/active_support/lazy_load_hooks.rb:26:in `on_load'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/haml-3.1.4/lib/sass/rails3_shim.rb:13:in `<top (required)>'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/sass-3.1.15/lib/sass.rb:19:in `<top (required)>'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/sass-3.1.15/lib/sass/version.rb:3:in `<top (required)>'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/haml-3.1.4/lib/haml/util.rb:347:in `try_sass'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/haml-3.1.4/lib/sass.rb:6:in `<top (required)>'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/compass-0.12.0/lib/compass/dependencies.rb:2:in `<top (required)>'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/compass-0.12.0/lib/compass.rb:5:in `block in <top (required)>'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/compass-0.12.0/lib/compass.rb:4:in `each'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/compass-0.12.0/lib/compass.rb:4:in `<top (required)>'
    from /home/rails/myapp/shared/bundle/ruby/1.9.1/gems/compass-0.12.0/lib/compass/rails.rb:2:in `<top (required)>'
    from /home/rails/myapp/releases/20120313170102/lib/foo.rb:1:in `<top (required)>'

foo.rb:1 is where I require 'compass'.

I dug around in Haml, Sass, Compass and Sprockets for a solution, but it feels like I'm missing something obvious here...

UPDATE:

When I add

require 'sass/rails'
require 'compass'

on top, the NameError: uninitialized constant Sass::Util doesn't happen, but the Sass::SyntaxError: File to import not found or unreadable: compass/typography/text/replacement. still happens when Sprockets::StaticCompiler.new(...).compile is called.

@scottdavis
Compass member

This is outside of the intended use case what exactly are you trying todo here? compile stylesheets for your application or for user uploaded sass?

@manuelmeurer

I'm trying to dynamically compile stylesheets based on user input.
Specifically, in my app you can style a widget (set colors etc.) and then a stylesheet is generated from that.

I found this blog post: http://www.simonecarletti.com/blog/2011/09/using-sprockets-without-a-railsrack-project/
and Guillermo Iguaran commented that StaticCompiler could be used for it...

@chriseppstein
Compass member

Pretty sure this is because the compass railtie didn't run and therefore it didn't configure sprockets.

@chriseppstein
Compass member

Closing this -- it's not a bug. Would welcome a wiki entry on how to accomplish this once you've got it figured out.

@manuelmeurer

Yes, you are probably right, the Compass Railtie (or Compass-Rails Railtie) didn't run.
Even if I include 'compass-rails' and/or include 'compass-rails/railties' it won't work.
Any idea why the Railtie doesn't run or how I can convince it to run? Really stuck here...

@manuelmeurer

The problem was (of course) that compass-rails was placed in the asset group in my Gemfile. Once I moved it out of there, this error disappeared.
I did a complete writeup about how to use the Sprockets::StaticCompiler to compile stylesheets dynamically here: http://www.krautcomputing.com/blog/2012/03/27/how-to-compile-custom-sass-stylesheets-dynamically-during-runtime/

@chriseppstein
Compass member

The asset group is the right place. you should require the asset group.

@manuelmeurer

Ok, thanks for the tip.

@antho1404

This is a really old issue but I had the same problem and I fixed the problem just by including compass paths with
Compass.sass_engine_options[:load_paths].collect { |path| path.try(:root) }.compact.
I use another way to compile it but it should work in that case. For more details I wrote a post about it http://microblog.anthonyestebe.com/2014-04-28/compile-your-scss-according-to-your-model-on-rails/.
Hope this can help someone ;)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.