11

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?

david.s
  • 11,283
  • 6
  • 50
  • 82

3 Answers3

27

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

david.s
  • 11,283
  • 6
  • 50
  • 82
Jeff
  • 536
  • 6
  • 8
  • 4
    Thanks, this is really helpful. Make sure you restart Visual Studio after changing the srv-less.js file. – Alexander van Trijffel Apr 17 '15 at 15:42
  • Hah. You know, it occurs to me - I'd have figured this out, and had much more success and less stress, if my workplace had let me access Github! Draconian policies have no place in the future in which we live. Sigh. –  Jun 05 '15 at 02:02
  • Additionally - I hope you made a pull request for your fix, Jeff M. –  Jun 05 '15 at 02:04
1

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.

1

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

david.s
  • 11,283
  • 6
  • 50
  • 82