Skip to content
This repository

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

Closed
rfkrocktk opened this Issue November 17, 2011 · 9 comments

7 participants

rfkrocktk Charles Lowell Natim Karol Bucek Rob Aldred diafygi Robert Buchholz
rfkrocktk

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

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

Karol Bucek
Collaborator

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 https://github.com/kares/less.rb if it behaves the same ?

rfkrocktk

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

Karol Bucek
Collaborator

with bundler in a Gemfile change: gem 'less.rb', :git => 'git://github.com/kares/less.rb.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

rfkrocktk

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

gem 'less.rb', :git >= 'git://github.com/kares/less.rb.git'

fails to run.

Rob Aldred

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
diafygi commented May 22, 2012

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

Example:

WORKING_PATH=/path/to/working
LESS_PATH=/path/to/less
CSS_PATH=$LESS_PATH
cd $LESS_PATH && lessc myfile.less > $CSS_PATH/myfile.css && cd $WORKING_PATH
Robert Buchholz
rbu commented June 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.

Karol Bucek
Collaborator
kares commented June 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 ...

Charles Lowell cowboyd closed this issue from a commit August 13, 2012
Karol Bucek 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)
f910958
Charles Lowell cowboyd closed this in f910958 September 02, 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.