Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 455
jedd.ahyoung Avatar asked Jan 29 '15 16:01

jedd.ahyoung


3 Answers

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

like image 109
Jeff Avatar answered Nov 17 '22 18:11

Jeff


From my experience, this error occurs when LESS attempts to output a CSS file from a LESS file, and the resulting CSS file is empty. In my case, this happened after removing some font-face declarations, which left the resulting CSS file empty. LESS would not compile until I added a class that would output to the CSS file.

Details may be found here: https://github.com/madskristensen/WebEssentials2013/issues/1696

I'm adding this to StackOverflow because I'm unable to access Github at my workplace. I hope this helps someone.

like image 27
jedd.ahyoung Avatar answered Nov 17 '22 19:11

jedd.ahyoung


You can also add in your less file an important comment /**/ or @charset "utf-8"; as described here https://github.com/madskristensen/WebEssentials2013/issues/1696

like image 1
david.s Avatar answered Nov 17 '22 19:11

david.s