@import not working with absolute file paths #65

ravinggenius opened this Issue Apr 22, 2011 · 10 comments


None yet
4 participants

I am trying to import a sass file via absolute file path, but keep getting an error that the file doesn't exist or cannot be read. This does not happen prior to version 3.1.0.alpha.249, so for now I have version 3.1.0.alpha.221 in my Gemfile (this is a Rails app). I can see that the file does actually exist. I'd be happy to test patches if needed.


chriseppstein commented Apr 22, 2011

I'm trying to imagine a use case where an absolute path doesn't result in pain, but not finding one. Please enlighten me.

It is for a CMS I'm working on. Each widget can add styles to a @mixin based on the widget's name. The @imports are then dynamically built, then the @includes are scoped to a class matching the widget's name, then the whole thing is rendered to CSS. Absolute @imports have worked just fine until 3.1.0.alpha.249; were they not supposed to this whole time?


chriseppstein commented Apr 24, 2011

In Sass 3.1, you can build a custom Importer to bring in dynamically generated code. This is vastly preferable to generating code to disk and then importing that.


chriseppstein commented Apr 24, 2011

Whether or not this should be supported is up to @nex3, I don't see a good use for it, it results in fragile stylesheets.


nex3 commented Apr 24, 2011

Absolute path imports seem to work fine for me. Can you post a backtrace, as well as which version of Ruby you're using?

This is not a blocker for 3.1.


nex3 commented Apr 24, 2011

Oh, please also post the exact Sass code you're using.

I am generating the following Sass dynamically, via https://github.com/ravinggenius/scratch_pad/blob/master/lib/sass_builder.rb. This gets converted to CSS, which is then stored in a publicly accessible file. Using compass-0.11.beta.7 and sass-3.1.0....

@charset 'utf-8'
$experimental-support-for-svg: true
$experimental-support-for-khtml: false
$experimental-support-for-microsoft: true
$experimental-support-for-mozilla: false
$experimental-support-for-opera: false
$experimental-support-for-webkit: false
@import '/home/thomas/.rvm/gems/ruby-1.9.2-p0@development/gems/scratch_pad-themes-default-0.0.1/lib/styles/_variables.sass'
@import 'compass/css3/font-face'
@import 'compass/reset/utilities'
@import 'compass/utilities/lists'
/* zenda license: /assets/theme/default/fonts/Zenda-fontfacekit/Paul%20Lloyd%20License%20Agreement.txt
@include font-face("zenda", font-files('/assets/theme/default/fonts/Zenda-fontfacekit/zenda-webfont.woff', woff, '/assets/theme/default/fonts/Zenda-fontfacekit/zenda-webfont.ttf', truetype, '/assets/theme/default/fonts/Zenda-fontfacekit/zenda-webfont.svg', svg), '/assets/theme/default/fonts/Zenda-fontfacekit/zenda-webfont.eot')
@import '/home/thomas/.rvm/gems/ruby-1.9.2-p0@development/gems/scratch_pad-widgets-system_menu-0.0.2/lib/styles/all.sass'
@import '/home/thomas/.rvm/gems/ruby-1.9.2-p0@development/gems/scratch_pad-themes-default-0.0.1/lib/styles/all.sass'
@media all
  @include global-reset
  @include reset-html5
    @include system_menu_all
  @include default_all


Sass::SyntaxError (File to import not found or unreadable: /home/thomas/.rvm/gems/ruby-1.9.2-p0@development/gems/scratch_pad-themes-default-0.0.1/lib/styles/_variables.sass.
Load paths:
  lib/sass_builder.rb:27:in `to_css'
  app/controllers/assets_controller.rb:40:in `styles'

Rendered /home/thomas/.rvm/gems/ruby-1.9.2-p0@development/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.0ms)
Rendered /home/thomas/.rvm/gems/ruby-1.9.2-p0@development/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (2.9ms)
Rendered /home/thomas/.rvm/gems/ruby-1.9.2-p0@development/gems/actionpack-3.0.7/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (8.8ms)

Thanks for trying to understand this and help me. I really appreciate the work you guys are doing.

@chriseppstein helped me work around this issue by converting the absolute paths to relative paths. Still not sure why the absolute paths wouldn't work.

what was the work around? I have a similar issue.

Using absolute paths the first file is imported correctly but instead of importing the second file it seems to import the first file again. (Strange, i know)

At first I suspected a caching issue but even with different filename the behavior remains.

@stefankroes I am converting all @import paths from absolute to relative with a bit of Ruby:

def prepare_path_for_import(path)
  reply = Pathname.new path
  # if the path is absolute, return a relative path
  reply.absolute? ? reply.relative_path_from(Pathname.new(Compass.configuration.sass_path)) : reply

I am generating this main Sass file in Ruby, so it was pretty easy to add this code to my project. I hope it helps.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment