Ubuntu – LESS CSS compilers returning blank

cssinstall-from-sourcenodejs

I am not even sure where to start debugging this. Months ago, I could happily compile my CSS from my LESS files. Today, I run either recess --compile test.less or lessc test.less and I just get a blank output. No errors. lessc test.less > test.css just creates a blank file. The twitter-bootstrap Makefile for LESS errors, all be it not helpfully.

I'm using the following simple test.less to debug:

@color: #4D926F;
#header {
  color: @color;
}
h2 {
   color: @color;
}

I'm on ubuntu 12.10, I used sudo apt-get install node-less to provide lessc, and installed recess from the directions on github (npm). Both just give me empty output.

Even lessc --version returns nothing.

 which lessc

shows

/usr/local/bin/lessc

and the file isn't empty.

Something must have happened to my node installation perhaps, but no idea how to debug this. apt-get remove --purge node-less and reinstalling didn't help.

Many thanks for the help or any tips on debugging!

Best Answer

In Ubuntu and other distributions, you should prefer the distribution packages instead of manually installing packages. So, first of all, you should remove the recess installed via npm:

sudo npm uninstall recess -g

Also remove the node-less package installed via apt-get, so that we can start with a clean environment:

sudo apt-get remove node-less

After issuing these two commands, ensure that the following files do not exist, and if they exist delete them:

/usr/bin/lessc
/usr/local/bin/lessc

Also check the following directories (and remove them if they exist):

/node_modules/less
/usr/bin/node_modules/less
/usr/node_modules/less
/usr/local/bin/node_modules/less
/usr/local/node_modules/less
~/.node_modules/less
~/.node_libraries/less

All that files and directories may be generated in various ways. Different installation methods lead to different directories used. Removing all that files is important to ensure that nothing conflicts: you should always have one, and just one, version of a software installed on your system. The only exception is when the distribution itself provides different versions of the same software (in this case, package are made so that they don't conflict with each other).

Now you have a clean environment and can install node-less:

sudo apt-get install node-less

Note that the node-less package does not ship /usr/bin/recess, just /usr/bin/lessc, so it's perfectly OK if recess --compile fails (or, better, it must fail).

If lessc still does not work, please check the output of which lessc. Remember: if it does return something different than /usr/bin/lessc, it means that you are not using lessc from the distribution package, but something else.