Skip to content

lessc fails to respect relative @import blocks when invoked with an abs. path #13

rfkrocktk opened this Issue Nov 17, 2011 · 9 comments

7 participants


The best way to explain this is to demonstrate it. As noted in this issue in another project which uses lessc provided here, lessc won't respect relative paths with the @import statement when invoked with an absolute path:

$ lessc /home/rfkrocktk/Desktop/myproject/src/myproject/web/static/styles/application.less
/var/lib/gems/1.8/gems/less-2.0.7/lib/less/loader.rb:46:in `error': file 'bootstrap-1.4/bootstrap.less' wasn't found. (Less::ParseError)
    from at Function.importer (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/index.js:114:13)
    from at Object.push (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:73:25)
    from at Object.<anonymous> (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/tree/import.js:30:17)
    from at Object.import (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:953:28)
    from at $ (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:103:24)
    from at Object.directive (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:967:29)
    from at $ (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:103:24)
    from at Object.primary (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:428:80)
    from at $ (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:103:24)
    from at Object.parse (/var/lib/gems/1.8/gems/less-2.0.7/lib/less/js/lib/less/parser.js:264:42)
    from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:65:in `parse'
    from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:13:in `calljs'
    from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:27:in `lock'
    from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:25:in `lock'
    from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:12:in `calljs'
    from /var/lib/gems/1.8/gems/less-2.0.7/lib/less/parser.rb:63:in `parse'
    from /var/lib/gems/1.8/gems/less-2.0.7/bin/lessc:22
    from /usr/local/bin/lessc:19:in `load'
    from /usr/local/bin/lessc:19

However, if I invoke it from the current directory, it works fine:

( cd /home/rfkrocktk/Desktop/myproject/src/myproject/web/static/styles && lessc application.less )

Evidently, it's not resolving paths relative to the target file, but relative to the directory in which lessc is invoked.

application.less above simply contains one line:

@import bootstrap-1.4/bootstrap.less

which exists in the bootstrap-1.4 folder in the same directory as application.less.

Natim commented Dec 5, 2011

I also have this issue, it would be great if lessc return a warning saying that the file coun't be found.

kares commented Dec 7, 2011

I think I might have fixed this as a side effect of my updates towards JRuby compatibility.
could any of you try building the gem from if it behaves the same ?


How can I build the gem? I'm sorry, I'm kind of new to building gems in Ruby :)

kares commented Dec 8, 2011

with bundler in a Gemfile change: gem 'less.rb', :git => 'git://'
and then bundle install
otherwise clone the repo, cd to it and gem build less.gemspec the gem will be baked in your cwd ...
then install the gem gem install less-2.0.7.gem


So, what command should I run? I'm on Linux.

gem 'less.rb', :git >= 'git://'

fails to run.

raldred commented Feb 16, 2012

This issue still exists in 2.0.9
Changing the dir of the less file before compiling is the only solution at the moment

diafygi commented May 22, 2012

If you need to include this in bash scripts, I wrap the lessc command with cd commands


cd $LESS_PATH && lessc myfile.less > $CSS_PATH/myfile.css && cd $WORKING_PATH
rbu commented Jun 27, 2012

a fix for this is in pull req #22, please merge this. issue still exists in 2.2.1. lessc from the npm does the right thing, which makes the ruby gem unsuitable as a drop-in replacement.

kares commented Jun 27, 2012

@rbu if you want to help try providing a failing spec, I've looked at the fix but there's no spec either + I'm guessing it should be reproducable without lessc as well ? if so than the fix should happen elsewhere since it will still fail when compiled using the API ...

@cowboyd cowboyd pushed a commit that closed this issue Sep 2, 2012
@kares kares bin/lessc more compatible with the JS version
- the main incompatibility being not supporting output to be specified as the node version does `lessc input.less output.css` we accept arbitrary (due backward compatibility but also to avoid confusion) input files and currently always print the output
- fixes #13 and #33 (makes #22 obsolete)
@cowboyd cowboyd closed this in f910958 Sep 2, 2012
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.