3

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?

Jørgen
  • 8,820
  • 9
  • 47
  • 67

2 Answers2

1

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

Luke Page
  • 8,136
  • 1
  • 20
  • 22
0

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)

Community
  • 1
  • 1
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758
  • I won't control all the input files here, so I can't base the solution on the editor used, I'm afraid. – Jørgen Aug 30 '12 at 11:32
  • Can't you make (automatically) a copy of those files and fix them before they enter your build chain ? – Denys Séguret Aug 30 '12 at 11:34
  • I guess it's a solution, but I guess I'm better off waiting for a new release or try to change the source code :) – Jørgen Aug 30 '12 at 11:42