Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

"LESS: Unexpected token u" error when compiling LESS file with empty result #1696

Open
NigelWhatling opened this issue Dec 4, 2014 · 17 comments

Comments

@NigelWhatling
Copy link

This may be related to Issue#1170 (which according to the comments has been fixed).

Recently updated to v2.5.3. When compiling a LESS file with no resulting CSS, a "LESS: Unexpected token u" error is given. I ran across this when making a change to the variables.less file of bootstrap. The file only contains variable definitions and is imported into other LESS files. This file no longer compiles.

As with Issue#1170, adding some element code (e.g. body { cursor:auto; }) to the file corrects the issue.

I have also found that adding an 'important' comment (e.g. /* bug fix comment */) fixed the issue (I'm guessing because these comments are retained in the output).

I'm working around the issue with the comment for now. But it would good to fix.

@Joebeazelman
Copy link

This problem still occurs under Update 4. Adding an "important" comment as stated fixes it. Here's my file:
@charset "utf-8";
/* CSS Document */

@import "variables.less";
@import "bootstrap.css";
@import "yamm.css";
@import "font-awesome.css";
@import "animate.css";
@import "jquery.flexisel.css";
@import "revolution-settings.css";
@import "lightbox.css";
@import "responsiveslides.css";
@import "main.less";
@import "responsive-adjustments.less";

/* bug fix comment

this file generates no code and causes Web Essentials to complain "Unexpected token u" adding an important comment or element fixes it

*/

Interestingly, the first comment doesn't solve the problem, but the second one does. What makes the second comment "important"? Does Web Essentials see the "bug" as a keyword?

@codepic
Copy link

codepic commented Dec 23, 2014

Interestingly I had this very same issue without any imports. But just by adding the @charset "utf-8"; on the top of the file, I got rid of the error: Unrecognized token u.

Also, we had an issue with the same project (not related to WE) today with a plain html file where the BOM was present in the file.

Perhaps this issue is related to the Byte Order Mark?

@roadsunknown
Copy link
Contributor

Also experiencing the issue. Mixins also do not generate any output and therefore throw the error. Adding @charset "utf-8"; does provide a temporary fix.

@carlosmunozrodriguez
Copy link

I'm also experiencing the issue. For me this comment also works.

/**/

@mojitocoder
Copy link

This is still a problem for me. I am using Web Essentials 2013 for Update 4.

The workaround I use for now is to add @charset "utf-8";

@rjgotten
Copy link

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.

@CheloXL
Copy link

CheloXL commented Feb 27, 2015

@rjgotten Thanks!!! That was driving me crazy!

@figalex
Copy link

figalex commented Feb 27, 2015

@rjgotten That fixed it! Thanks!

@Joebeazelman
Copy link

Is there a reason why this fix isn't included in the latest updates? Surely, if I was the developer I would want to include it the fix. The old comment workaround no longer works.

For this to work correctly, you must restart visual studio after making the changes to the JavaScript file. I did so, but I hit upon this error JSON Schema: Couldn't parse System.String[] as a valid regex when I tried to use compile all less files. I went back and removed some of my old comment workarounds and when I saved it, it mysteriously worked.

Is this the current state of software? Back in the old days, we didn't have a fraction of the tools and computing power we have today and software generally worked very well, even when written in assembly language.

@rjgotten
Copy link

rjgotten commented Mar 4, 2015

Is this the current state of software?

No, it's just Web Essentials falling flat on its face every other release due to a chronic shortage of proper unit tests on Visual Studio extension with a scope wide enough that it has begun to follow the god class anti-pattern.

Web Essentials should be torn apart into smaller modules that can be invididually tested and individually updated. It's been mentioned before a few times...

@gligoran
Copy link

Thanks you @rjgotten, this fixed it for me too.

I hope the Web Essentials team (@madskristensen) implements this fix with the next update.

P.S. If anyone in the future is wondering, a restart of Visual Studio is required. At least for me it was.

@MCluck90
Copy link

👍 @rjgotten's solution worked for me. This should really be implemented in the next update.

@behrangsa
Copy link

👍 Looking forward for this fix!

@nbarbettini
Copy link

@rjgotten Thanks for the fix. This was a a really confusing error, but it's working fine thanks to you.

Hoping this is fixed permanently in a future release!

@behrangsa
Copy link

@rjgotten 👍

@RichardJECooke
Copy link

Why is this still not in the release version months later? :-(

@niklasHagner
Copy link

Unbelievable that this still hasn't been fixed.
I've had to include a description of the fix where you change one line in srv-less.js (as suggested by @rjgotten ) to the developer documentation of a few projects at my company.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests