Sass import error in Rails 3 app - "File to import not found or unreadable: compass"
Asked Answered
D

7

24

I have a Rails 3 app on which I successfully ran compass init rails ./ --using blueprint. I can @import files from the /stylesheets directory, but I get an error when I try to @import compass.

Right now the app has two simple sass files:

common.scss

$body-background: blue;

main.scss

@import "common";
//@import "compass";

body { 
  background: $body-background; 
}

With the @import "compass" line commented out, this works -- I get a blue background, so I know Sass is working.

If I uncomment the line, and try to import compass or blueprint or anything else, I get an error like this.

Syntax error: File to import not found or unreadable: compass.
              Load paths:

                /Users/eric/path/to/myrailsapp/app/stylesheets
        on line 2 of /Users/eric/path/to/myrailsapp/app/stylesheets/main.scss

1: @import "common";
2: @import "compass";
3: 
4: body { 
5:  background: $body-background; 
6: }

I had through maybe I had to explicitly tell Sass where to find the Compass gem, so I added an add_import_path line to config/compass.rb:

require 'compass'
require 'html5-boilerplate'

project_type = :rails
project_path = RAILS_ROOT if defined?(RAILS_ROOT)
add_import_path "/Library/Ruby/Gems/1.8/gems/"  # unfortunately this has no effect

http_path = "/"
css_dir = "public/stylesheets"
sass_dir = "app/stylesheets"
images_dir = "public/images"
javascripts_dir = "public/javascripts"
cache_dir = "tmp/sass-cache"

http_images_path = "/images"
http_stylesheets_path = "/stylesheets"
http_javascripts_path = "/javascripts"

I have been googling for two days, and can't determine why I'm having this problem with basic @import statements. How do I tell Sass where to find the Compass and Blueprint libraries?

Diclinous answered 14/5, 2011 at 23:11 Comment(0)
D
4

Okay, after help from the amazing Chris Eppstein I was able to find the offending line. In config/environments.rb I had this line:

Sass::Plugin.options[:template_location] = {
"#{RAILS_ROOT}/app/stylesheets" => "#{RAILS_ROOT}/public/stylesheets"
}

With the currently versions of Rails (I have 3.0.7) and Compass (0.11.1) this line is not necessary. I added it after following a tutorial. If sass can't find compass, it might be because this line is messing up your Sass::Plugin.options[:template_location].

Diclinous answered 22/5, 2011 at 20:29 Comment(0)
C
21

I was getting this error.

I changed this line in my application.rb from:

Bundler.require(:default, Rails.env) if defined?(Bundler)

to:

Bundler.require(*Rails.groups(:assets => %w(development test))) if defined?(Bundler)

Also, make sure the files are names something.css.sass NOT something.sass

And one other thing, I had an old compass.rb file in my config directory which isn't needed in Rails 3.2. Deleting that also solved this problem for me.

Cellule answered 26/1, 2012 at 16:45 Comment(1)
I created a new Rails 3.2.8 project today and compass.rb was the problem. I didn't change anything in application.rb. So delete compass.rb first.Nelda
C
9

I fixed this problem by switching to the compass-rails gem instead of the compass gem in my Gemfile (don't forget to reboot your server). Just in case someone might come across here.

Colman answered 14/5, 2011 at 23:11 Comment(0)
S
5

I fixed this error after banging my head over it

I commented this line in my application.rb from:

Bundler.require(*Rails.groups(:assets => %w(development test))) if defined?(Bundler)

and uncommented:

Bundler.require(:default, :assets, Rails.env) if defined?(Bundler)    

I am using Rails 3.2.11

Spikenard answered 8/2, 2013 at 14:0 Comment(1)
If you've added a new environment, adding to the %w(development test), such as %w(development test new_env_name) should be sufficient to get assets to load.Bentley
D
4

Okay, after help from the amazing Chris Eppstein I was able to find the offending line. In config/environments.rb I had this line:

Sass::Plugin.options[:template_location] = {
"#{RAILS_ROOT}/app/stylesheets" => "#{RAILS_ROOT}/public/stylesheets"
}

With the currently versions of Rails (I have 3.0.7) and Compass (0.11.1) this line is not necessary. I added it after following a tutorial. If sass can't find compass, it might be because this line is messing up your Sass::Plugin.options[:template_location].

Diclinous answered 22/5, 2011 at 20:29 Comment(0)
D
3

I fixed this problem on my Rails 3.2.0 server by moving out gem 'compass-rails', '~> 1.0.1' from the :assets group in the Gemfile, from a tip in https://github.com/Compass/compass-rails/issues/19.

Dominations answered 30/5, 2012 at 22:4 Comment(1)
This didn't work for me on Rails 3.2.13 and compass-rails 1.0.3.Atterbury
I
2

The @import command in Sass imports .scss or .sass files, not .css files.

It looks like something was missed in the install. (maybe the line compass install blueprint?) I followed the steps here: http://compass-style.org/reference/blueprint/ and was unable to recreate the issue.

Ierna answered 15/5, 2011 at 2:54 Comment(2)
Right, I'm trying to include the regular compass and blueprint (scss) files. The "compass init" line above install blueprint. Just to confirm I ran the command again -- you can see in the output below that compass thinks everything is installed.Diclinous
$ compass install blueprint identical app/stylesheets/screen.scss identical app/stylesheets/partials/_base.scss identical app/stylesheets/print.scss identical app/stylesheets/ie.scss identical public/images/grid.pngDiclinous
P
0

I fixed this error like this:

In application.rb I had

Bundler.require(:default, Rails.env) if defined?(Bundler)  

and changed to

Bundler.require(:default, :assets, Rails.env) if defined?(Bundler)

This was after updating a project from 3.0.3 to 3.2.13

Panjandrum answered 15/6, 2013 at 18:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.