LESS compiler does not resolve imports with relative paths


Sample scenario: Download Bootstrap as LESS files and try to load it using Combinator LESS file support. It reports "You are importing a file ending in .less that cannot be found."

The reason is that all imports in Bootstrap have relative paths (otherwise it would not be usable in all installations), but the LESS compiler isn't configured to set the "current directory" to the compiled file location.

It needs to be configured.


Piedone wrote Sep 15, 2013 at 10:20 PM

It seems settings the directory is not trivial: https://github.com/dotless/dotless/issues/204 I'll take a look but if you have a solution already don't keep it to yourself :-) (the DotLess code in Combinator is very simple, see LessPreprocessor).

Dunross wrote Sep 15, 2013 at 10:53 PM

Yep, it appears to be nontrivial.. :-/ I haven't made a fix unfortunately - I precompile the LESS files in other tools instead. It would be nice to have it working, but I'm too busy working on other modules now.. :-(

Piedone wrote Sep 16, 2013 at 10:24 AM

Could you describe what exactly the code you're trying is and how it fails? Because I tried just now and it work as expected:
@import "Folder/Test";
This imports the less file under Folder/Test.less.

The only gotcha is that you have to import files without the .less extension added to the path for some reason. If you're using bootstrap.less directly this means you have to provide an alternative version where the .less extensions are stripped, but that's it.

Another issue is BTW that there's no released version of DotLess with Less 1.4 support yet... This also means no Bootstrap 3 usable. Speaking of Bootstrap you might want to take a look at this: https://pgbootstrapbasetheme.codeplex.com/

Dunross wrote Sep 16, 2013 at 10:52 AM

aha, lol, I haven't tried to import it without extensions... :-) However, if there isn't support for BS 3.0, I cannot use it anyway.. :-( But thanks for the investigation!

Piedone wrote Sep 16, 2013 at 11:37 AM

I'll update DotLess once it's released.

MattGC wrote May 29, 2015 at 2:14 PM

Seems a shame that we are still left waiting for a fix.

For now, could we simply look for @import in the string being parsed and replace with the HostingEnvironment.MapPath(importpath)? That seems to work fine unless I'm missing something.


kerray wrote Sep 30, 2015 at 12:11 PM

I'm attempting to use Bootstrap's .less files contained in PJS.Bootstrap, but importing relative paths still fails, and I can't even do it when I strip the ".less" part of the imports... any news on this front please?