Search code examples
lessweb-essentials

LESS Compiler: Unexpected token u


When I attempt to compile a LESS template in Visual Studio using Web Essentials, I receive an error that says "Unexpected token u" with no file name, no line number, and no column number. Why is this happening?


Solution

  • Go to %USERPROFILE%\AppData\Local\Microsoft\VisualStudio\12.0\Extensions which is the folder where per-user Visual Studio extensions reside. WebEssentials will be located in a subfolder with a randomly generated name.

    From inside the WebEssentials folder, open up the file Resources\nodejs\tools\server\services\srv-less.js and go to line 65, which reads:

    map = JSON.parse(output.map);
    

    The problem is source map output may be the undefined value. JSON.parse can only parse strings, so it casts that to the string value "undefined" before parsing, but JSON does not recognize that as valid token. (It only understands the null value, not the undefined value.)

    So... change line 65 to read:

    map = JSON.parse(output.map || "null");
    

    And voilà; LESS compilation on files with empty output works again.

    Source: https://github.com/madskristensen/WebEssentials2013/issues/1696