D3.js: "Unused syntaxError: Unexpected ILLEGAL token"?

I just downloaded D3.js from d3js.org (link to the zip file), unzipped it and referenced it in the following HTML page:

<html> <head> <title>D3 Sandbox</title> <style> </head> <body> <script src="/d3.v3.js"></script> </body> </html> 

But when I load this page, my console (in Chrome) gives me this error:

 Uncaught SyntaxError: Unexpected token ILLEGAL: line 2 

I do not like the characters pi and e at the beginning of the file . Errrr ... what can I do about this? I am serving a file using python SimpleHTTPServer.

Update: yes, I know that I can just reference the CDN version, but I would prefer to use the file locally.

+72
javascript
Mar 06 '13 at 0:57
source share
5 answers

Try specifying UTF-8 encoding in the HTML host document:

<meta http-equiv="content-type" content="text/html; charset=UTF8">

+128
Mar 30 '13 at 9:42 on
source share

This sounds like an encoding problem. I recommend Absolute Minimum Every software developer Absolutely, should know positively about Unicode and character sets (no excuses!) . Despite its somewhat condescending name, it contains very useful information. In particular, it looks like your server is serving the wrong encoding d3.v3.js file.

+9
Mar 06 '13 at 1:03
source share

Add 'charset = "utf-8"'

 <script src="/d3.v3.js" charset="utf-8"></script> 
+4
Aug 24 '14 at 4:53 on
source share

I tried setting the encoding in the document and in the script tag, but Chrome doesn't seem to care. Not sure if I am doing something wrong.

I found success by running it using uglify with the -ascii-only option.

UPDATE: disables the View-> Encoding parameter in Chrome, but not in Auto-Detect, but in some western encoding. I don’t know why, but the change that resolved the problem. It is ridiculous that this setting will surpass the charset property directly on the script tag. Given that users may be in the same situation and not be able to understand this, I will still use uglify to ensure success.

+4
Sep 25 '14 at 20:20
source share

Check if there is a plus sign between all of your string concatenations if you do not create this error.

0
Aug 01 '15 at 3:24
source share



All Articles