Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Undefined variable: "$em-base" #632

Closed
flynfish opened this issue Jan 20, 2015 · 28 comments
Closed

Undefined variable: "$em-base" #632

flynfish opened this issue Jan 20, 2015 · 28 comments

Comments

@flynfish
Copy link

I'm getting this error when assets:precompile runs...

The deploy has failed with an error: #<SSHKit::Runner::ExecuteError: Exception while executing on host cfs.staging: rake exit status: 1
rake stdout: Nothing written
rake stderr: /usr/local/rvm/rubies/ruby-2.1.2/bin/ruby /usr/local/rvm/gems/ruby-2.1.2@cfs-web/bin/rake assets:precompile:all RAILS_ENV=staging RAILS_GROUPS=assets
rake aborted!
Sass::SyntaxError: Undefined variable: "$em-base".
  (in /usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/bourbon-4.1.1/app/assets/stylesheets/functions/_modular-scale.scss)
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/bourbon-4.1.1/app/assets/stylesheets/functions/_modular-scale.scss:21
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/script/tree/variable.rb:49:in `_perform'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/script/tree/node.rb:50:in `perform'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/script/tree/funcall.rb:170:in `perform_arg'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/script/tree/funcall.rb:124:in `block in _perform'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/script/tree/funcall.rb:124:in `each'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/script/tree/funcall.rb:124:in `each_with_index'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/script/tree/funcall.rb:124:in `each'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/script/tree/funcall.rb:124:in `map'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/script/tree/funcall.rb:124:in `_perform'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/script/tree/node.rb:50:in `perform'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/perform.rb:468:in `visit_variable'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/base.rb:36:in `visit'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/perform.rb:158:in `block in visit'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/stack.rb:79:in `block in with_base'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/stack.rb:115:in `with_frame'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/stack.rb:79:in `with_base'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/perform.rb:158:in `visit'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/base.rb:52:in `block in visit_children'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/base.rb:52:in `map'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/base.rb:52:in `visit_children'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/perform.rb:167:in `block in visit_children'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/perform.rb:179:in `with_environment'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/perform.rb:166:in `visit_children'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/base.rb:36:in `block in visit'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/perform.rb:186:in `visit_root'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/base.rb:36:in `visit'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/perform.rb:157:in `visit'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/visitors/perform.rb:8:in `visit'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/root_node.rb:36:in `css_tree'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/tree/root_node.rb:20:in `render'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-3.4.10/lib/sass/engine.rb:268:in `render'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sass-rails-3.2.6/lib/sass/rails/template_handlers.rb:106:in `evaluate'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/tilt-1.4.1/lib/tilt/template.rb:103:in `render'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/context.rb:193:in `block in evaluate'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/context.rb:190:in `each'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/context.rb:190:in `evaluate'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/processed_asset.rb:16:in `initialize'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/base.rb:18:in `new'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/base.rb:18:in `block in build_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/base.rb:270:in `circular_call_protection'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/base.rb:14:in `build_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/index.rb:93:in `block in build_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/caching.rb:19:in `cache_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/index.rb:92:in `build_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/base.rb:169:in `find_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/bundled_asset.rb:12:in `initialize'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `new'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/base.rb:22:in `build_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/index.rb:93:in `block in build_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/caching.rb:19:in `cache_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/index.rb:92:in `build_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/base.rb:169:in `find_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/index.rb:14:in `find_asset'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:41:in `block in compile'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/base.rb:219:in `block in each_logical_path'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/base.rb:206:in `block (2 levels) in each_file'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/base.rb:196:in `each'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/base.rb:196:in `each_entry'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/base.rb:204:in `block in each_file'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/base.rb:203:in `each'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/base.rb:203:in `each_file'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/sprockets-2.2.3/lib/sprockets/base.rb:217:in `each_logical_path'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/sprockets_overrides/static_compiler.rb:29:in `compile'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/tasks/assets.rake:108:in `internal_precompile'
/usr/local/rvm/gems/ruby-2.1.2@cfs-web/gems/turbo-sprockets-rails3-0.3.14/lib/turbo-sprockets/tasks/assets.rake:115:in `block (3 levels) in <top (required)>'
Tasks: TOP => assets:precompile:all
(See full trace by running task with --trace)
rake aborted!
@flynfish
Copy link
Author

The issue was because I had config.assets.precompile += %w( *.js *.css ) in my environment file. If I remove *.css it now works.

@achiinto
Copy link

@flynfish are we not supposed to precompile the css for production? If I don't precompile, it did not show up at production. If I try, I am getting this same error.

@achiinto
Copy link

@flynfish I guess I am not supposed to expect anything precompiled for scss file. Just my server setup problem then. 🐸

@smenor
Copy link

smenor commented May 28, 2015

Really @achiinto ?!? If we can't precompile then I can't use bourbon

@flynfish
Copy link
Author

@achiinto @smenor yea, I stopped trying to use bourbon because it wouldn't precompile for me...I didn't have time to figure out the issue or wait for it to get fixed..

@smenor
Copy link

smenor commented May 28, 2015

@flynfish it's kinda depressing and seems like it should be a priority because (a) probably not that hard of a thing to fix and (b) since it's broken we just went with an in-house (/ semi-kludgy) solution that gets the job done. Now even if this issue is resolved, we'd have the wasted time of rolling our own plus it'd take us more development time to switch to bourbon. I assume we're not alone there.

@sadaf2605
Copy link

remote: Sass::SyntaxError: Undefined variable: "$em-base".
remote: /tmp/build_b1c8ba5d0cbe89f021a4171d18c73441/vendor/bundle/ruby/2.0.0/gems/bourbon-4.2.3/app/assets/stylesheets/functions/_modular-scale.scss:21
remote: /tmp/build_b1c8ba5d0cbe89f021a4171d18c73441/vendor/bundle/ruby/2.0.0/gems/sass-3.4.14/lib/sass/script/tree/variable.rb:49:in `_perform'

@tysongach
Copy link
Contributor

Can anyone share their code? Also, did you remove all Sprockets directives from your application.scss?

@smenor
Copy link

smenor commented Jul 9, 2015

I ripped bourbon out and rolled my own version of the functions I needed a couple months back, and I us application.css but doesn't it seem a bit extreme to load my scss files, but doesn't it seem a bit extreme to ask people to monkey with their use of Sprockets just to use a «lightweight» library ?

@tysongach
Copy link
Contributor

@sebmor Not sure I’m following or understand your comment above…

But in regards to Sprockets, Step 4 of our installation instructions have you remove those directives because we have Sass do the concatenating/importing instead. Here’s a great article on why that is » http://pivotallabs.com/structure-your-sass-files-with-import/

@smenor
Copy link

smenor commented Jul 9, 2015

Maybe I'm missing something but I don't actually see a «why» there - merely instructions on the «what» and «how».

That's fine but it's not very compelling. I like the idea of using the native SASS @import but I have 19 stylesheets in my main Rails app. You're saying: go through all of those and switch to @import everywhere. That's almost certainly not just a search/replace job and will have side-effects.

Not to get ranty here but what's really annoying is that this used to work for me with the asset pipeline / without that /\ surgery and then broke at some point so obviously it's possible to make it work. Given that I've already wasted a lot of time on this (first trying to make Bourbon work and then writing my own functions), telling me that maybe if I monkey around and potentially break a lot of things that are already working and then /maybe/ it'll work does not encourage me.

@joshuaogle
Copy link
Contributor

@smenor The why is the Sprockets methods import the stylesheets in alphabetical order, which not only messes with the cascading part of stylesheets, but if you are using Sass mixins then you may end up trying to use a mixin or function before it is defined. It's an issue that comes up with Sprockets + Sass in general.

If you need to be picky about your import order, it's best to use Sass's @import methods instead.

@smenor
Copy link

smenor commented Jul 9, 2015

Thanks - that's definitely good to know (and an odd choice on their part). That does make me want to (eventually) switch over to @import everywhere

Still not quite sure why I can't just @import bourbon without running into the $em-base error though :)

@tysongach
Copy link
Contributor

@sebmor Yeah, I mean it is a bummer, don’t get me wrong. It makes our installation a bit more complex by adding an extra step and possibly making authors change the way they do things…but it’s just the situation we’re in. Sprockets does things a certain way when importing and it doesn’t work nicely alongside Sass @import’s. There are certain inter-dependencies within Bourbon and Sass’s @import gives us the ability to control things like that.

Thank you for expressing that we could be more clear in our instructions as to why we need Sprockets directives to be removed. I’ll put up a PR tomorrow to try to make that more clear.

@AntonFilipko
Copy link

@tysongach It still doesn't work for me. I use activeadmin which uses bourbon gem. I removed all "require" and still no luck. Any advice?

@hansottowirtz
Copy link

I just use gem env to find out where my gems are installed, and I add $em-base: 16px to .../gems/bourbon-x.x.x/app/assets/stylesheets/functions/_modular-scale.scss at the top.

@smenor
Copy link

smenor commented Jan 3, 2016

And that doesn't seem like a horrible kludge to you ?

Le 2 janv. 2016 à 15:37, Hans Otto Wirtz notifications@github.com a écrit :

I just use gem env to find out where my gems are installed, and I add $em-base: 16px to .../gems/bourbon-x.x.x/app/assets/stylesheets/functions/_modular-scale.scss at the top.


Reply to this email directly or view it on GitHub.

@hansottowirtz
Copy link

@smenor It does, but I didn't find anything better for now.

@itelmenko
Copy link

I have same error. Please, reopen issue.
Now I used gem env like hansottowirtz. And I have added $em-base: 16px to .../gems/ruby-2.2.3@bb4.0/gems/bourbon-4.2.7/app/assets/stylesheets/functions/_modular-scale.scss

@nguyenchiencong
Copy link

This is a nightmare. Will have to stop using bourbon

@tysongach
Copy link
Contributor

@nguyenchiencong @izumeroot @hansottowirtz @AntonFilipko Can any of you share your code? Are you all using within a Ruby on Rails app, or something else? What version of Bourbon?

@itelmenko
Copy link

Look like I have fixed it. The problem was in my config/initializers/assets.rb file.
I had these lines in it:

Rails.application.config.assets.precompile <<
    Proc.new { |filename, path|
      (path =~ /app\/assets/ || path =~ /lib\/assets/ || path =~ /vendor\/assets/)  && !filename.include?('active_admin') #%w(.js .css .jpg .jpeg .png .gif .ico).include?(File.extname(filename)) && !filename.include?('active_admin')  #
    }

And I think I had error because Asset Pipeline compiled scss-files of bourbon not in correct context.

Now I have changed my assets.rb file:

%w( entries ).each do |controller|
  Rails.application.config.assets.precompile += ["#{controller}.js", "#{controller}/*.js", "#{controller}.css", "#{controller}/*.css"]
end

Rails.application.config.assets.precompile += %w( custom.css )
Rails.application.config.assets.precompile += %w( theme/style.css )
Rails.application.config.assets.precompile += %w( theme/blue.css )
Rails.application.config.assets.precompile += %w( scaffolds.css )
Rails.application.config.assets.precompile += %w( sessions.css )
Rails.application.config.assets.precompile += %w( sessions.js )

And I have not error.

@tysongach
Copy link
Contributor

@izumeroot In your application.css.scss (or whatever your main manifest file is), do you have any Sprockets directives, like *= require_tree?

@itelmenko
Copy link

application.css.scss:

/*
 *
 *= require_self
 *= require twitter/bootstrap
 *= require jquery-ui-bootstrap
*/

@tysongach
Copy link
Contributor

tysongach commented May 12, 2016

@izumeroot Where are you importing Bourbon? Also within application.css.scss? If there is more to that file, can you post the entire contents?

@itelmenko
Copy link

It is imported by active_admin gem. I use active admin.
But as I wrote, I have fixed this error. My problem was in config/initializers/assets.rb file.
Do you think it is not correct way?

@hansottowirtz
Copy link

hansottowirtz commented May 12, 2016

I do not have any sprockets directives, I just have a dependencies.scss file with @import 'bourbon'; at the top, and I have @import 'dependencies'; in every other scss file. I link to those scss files in my application.html.erb.

It is indeed in Ruby on Rails, and I always use the latest version of bourbon (4.2.7).

Every time I update bourbon, I just put $em-base: 16px; at the top of ~/.rbenv/versions/x.x.x/lib/ruby/gems/x.x.x/gems/bourbon-x.x.x/app/assets/stylesheets/functions/_modular_scale.scss

@hansottowirtz
Copy link

hansottowirtz commented May 12, 2016

My assets.rb file:
Rails.application.config.assets.precompile += %w(*.js *.css)
This causes the application to precompile everything when running RAILS_ENV=production bundle exec rake assets:precompile

When precompiling _modular_scale.scss, it doesn't find the $em-base at $modular-scale-base: em($em-base) !default;. I think adding something like $em-base: 16px !default; above it would be great.

It might not be best practice to use the %w(*.js *.css), but it should work.

If you are not adding the default rule, I would certainly recommend not using %w(*.js *.css) in the readme.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

10 participants