I use the less compiler with node.js and I know there is an issue with the files encoded in UTF-8 with BOM. For this, this workaround works great:
data = data.replace(/^\uFEFF/, ''); // Strip potential BOM
However, when importing files, using @import
statements still gives a syntax error on first line. Are there any way to work around this as well?
The BOM will be stripped in the next version of less.js - 1.3.1. You can also try it out on the github source pages.
https://github.com/cloudhead/less.js/commit/6696368eb351824f33dc0aac67143d8ea80a085a
A BOM in an UTF-8 file makes no sense.
You should fix the source files as many other tools will (rightly) have problems with this BOM. All serious editors are able to write UTF-8 files without BOM.
If you must receive and handle such files, you should automaticaly fix them using for example (operating on a work copy if needed) :
awk '{if(NR==1)sub(/^\xef\xbb\xbf/,"");print}' INFILE > OUTFILE
(taken from Using awk to remove the Byte-order mark)