dotless fails on any variables or mixins(functions). variable @background-dark is undefined

1.4k Views Asked by At

If I call any of my variables in dotless, or mixins for that matter, the resulting CSS file is empty.

My setup is as follows:

  1. I have an import file which imports all of my other dotless based css files
  2. The first import is variables
  3. The second import is mixins (methods)
  4. Followed by any other files I need

So the file 00.1.import.less will have the following content:

@import "00.2.variables";
@import "00.3.methods";
@import "00.4.init";
@import "01.1.html";

When I copy the resulting link to a new tab it shows:

variable @background-dark is undefined on line 24 in file '/Content/00.1.import.less':

 [23]: @import "11.1.p";
 [24]: @import "13.1.a";
       ---------------^
 [25]: @import "13.2.a-login";

Strange thing is that that line is just that, an import line. That file doesn't make use of any variables or mixins at all. neither does the next file. Currently I'm testing a variable/mixin one single file.

If I hit F5 the next exception I get is:

Value does not fall within the expected range.

Stack Trace:    

[ArgumentException: Value does not fall within the expected range.]
   System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal(Int32 errorCode, IntPtr errorInfo) +0
   System.Web.Hosting.IIS7WorkerRequest.SetKnownResponseHeader(Int32 index, String value, Boolean replace) +150
   System.Web.HttpHeaderCollection.SetHeader(String name, String value, Boolean replace) +219
   System.Web.HttpHeaderCollection.Add(String name, String value) +23
   System.Web.HttpResponse.AppendHeader(String name, String value) +189
   System.Web.HttpResponseWrapper.AppendHeader(String name, String value) +16
   dotless.Core.Response.CssResponse.HandleCompression() +646
   dotless.Core.Response.CssResponse.WriteCss(String css) +79
   dotless.Core.Loggers.AspResponseLogger.Log(String message) +50
   dotless.Core.Loggers.Logger.Log(LogLevel level, String message) +80
   dotless.Core.Loggers.Logger.Error(String message) +43
   dotless.Core.LessEngine.TransformToCss(String source, String fileName) +562
   dotless.Core.ParameterDecorator.TransformToCss(String source, String fileName) +420
   dotless.Core.HandlerImpl.Execute() +152
   dotless.Core.LessCssHttpHandler.ProcessRequest(HttpContext context) +123
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +100
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +75

Example Variable Problem: declaration

@background-dark: #404040;

usage

div#top
{
    height:125px;
    border-top: 2px solid #158fa6;
    background:@background-dark;
}

This fails no matter what I do.

Anyone know where I'm going wrong?

2

There are 2 best solutions below

6
On

There seem to be 2 problems.. First off this should be reported to http://github.com/dotless/dotless rather than on stack overflow, but anyway I'll continue.

The caching issue seems to be an exception setting headers - I haven't see that before and it needs investigating to work out what is going wrong.

The variable problem is maybe suffering from a bug we had prior to 1.3.0.5 where it didn't report errors in imported files correctly. If you are not on 1.3.05, please upgrade and try again.

0
On

Jacques,

First, this is not an answer as much as an explanation.

It seems that you are running into the same compile, bundle, minify order issue I am.

Dotless - Can't reference less variable in separate file with MVC Bundling

The problem that I have, and am trying to resolve, is that I am referencing variables and mixins in separate files (included before being referenced), and they are not found. Since file compilation is handled individually, the file that is being compiled has no knowledge of previously compiled files. In this case, dotless returns no content to be bundled.

I have written a couple of different modifications to the process method to bundle manually and then minify, but dotless doesn't seem to have a functional method for compiling less without a physical file name to reference.

Please let me know if I'm off base here.