I just switched from using a local copy of the minified version of d3.v3 to the development version. It worked fine when using the minified version, but using my local copy of http://d3js.org/d3.v3.js gives me the error in the title, referencing this line:
var € = Math.PI, µ = 1e-6, d3_radians = € / 180, d3_degrees = 180 / €;
When I include the hosted file, it works fine.
The error Uncaught SyntaxError: Unexpected token < is most commonly caused by your site's code referring to an asset that is no longer available. Most commonly, this is due to a filename change in assets generated during your build.
The "Uncaught SyntaxError: Unexpected identifier" error occurs for 2 main reasons: Misspelling a keyword, e.g. Let or Class instead of let and class . Having a typo in your code, e.g. a missing or extra comma, parenthesis, quote or bracket.
The Javascript SyntaxError occurs when trying to interpret code that is not syntactically valid. It is thrown when the Javascript engine comes across tokens or token order that does not conform to Javascript syntax when parsing code.
The problem is that you are serving D3 with the ISO-8859-1 character encoding (often the browser default), whereas D3 must be served with UTF-8 encoding. Typically this happens because you are missing a meta tag at the top of the loading HTML page:
<!DOCTYPE html> <meta charset="utf-8">
The meta-specified charset is required because d3js.org is served by GitHub Pages and does not specify a charset in the Content-Type response header. The charset is therefore inferred from the loading HTML document.
If you prefer, you can specify a charset attribute on the script tag. Make sure you clear your browser cache before testing, as the cached copy will retain the character encoding from when it was originally accessed:
<script src="http://d3js.org/d3.v3.js" charset="utf-8"></script>
The error does not occur with the minified version because the variable names are replaced with ASCII equivalents. (I don't recall offhand if UTF-8 characters in format strings are likewise replaced with escape sequences, but I still recommend serving D3 as UTF-8 in all cases.)
Encoding problems can also happen if you downloaded D3 by viewing the source in your browser and then using copy-paste, which is why I recommend downloading d3.v3.zip.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With