13

I am getting some errors when trying to run yuicompressor.

it says:

[error] 1:2:illegal character
[error] 1:2:syntax error
[error] 1:3 illegal character

Could this be because I am saving it as the wrong encoding or something?

Zanon
  • 29,231
  • 20
  • 113
  • 126
mrblah
  • 99,669
  • 140
  • 310
  • 420

6 Answers6

21

I have seen issues with YUICompressor and files that are saved in UTF-8 with the Byte Order Mark (BOM). The default for Visual Studio 2008 seems to be to save them this way. To solve it, I had to save the file with a different encoding. In VS2008, this was File - Advanced Save Options - Encoding : Unicode (UTF-8 without signature).

Kevin Hakanson
  • 41,386
  • 23
  • 126
  • 155
  • Anyone know if it's possible to use this encoding when outputting a file via Powershell? I'm concatenating my files with Powershell, and like most apps it likes to use the BOM. – JoshNaro Nov 22 '10 at 16:24
8

I ran across this issue today. Another fix is to provide the --charset utf-8 option on the command line.

Liam
  • 27,717
  • 28
  • 128
  • 190
3

In addition to saving under "UTF-8 without signature encoding", I had to switch to Windows style line endings (CR LF).

0

While viewing the .js file in Visual Studio 2008... File -> Advanced Save Options -> Unicode (UTF-8 without signature).

Kris Krause
  • 7,304
  • 2
  • 23
  • 26
0

I've had the same problem with encodings using the .NET version of the YuiCompressor.

Fixed adding the EncodingType="UTF8" in my configuration file:

<CssCompressorTask        EncodingType="UTF8" SourceFiles="@(CssFiles)"        OutputFile="path\styles.min.css" />
<JavaScriptCompressorTask EncodingType="UTF8" SourceFiles="@(JavaScriptFiles)" OutputFile="path\scripts.min.js" />

For more encoding options, see the docs.

Zanon
  • 29,231
  • 20
  • 113
  • 126
0

Just in case anyone is using Powershell to concatenate files, I used the following Powershell script to circumvent this problem:

Get-Content `
JavaScript/file01.js,`
JavaScript/file02.js,`
JavaScript/file03.js `
 | Set-Content JavaScript/Concat.js -Encoding Ascii

java.exe -jar ../../yuicompressor/build/yuicompressor-2.4.2.jar JavaScript/Concat.js -o JavaScript/Concat.min.js preserve-semi --charset ascii --type js

Notice the ascii encoding parameters on both the concatenation and YUICompressor call.

JoshNaro
  • 2,047
  • 2
  • 20
  • 40