Browserify: Unicode characters get messed up

Created on 24 Mar 2013  ·  11Comments  ·  Source: browserify/browserify

For example d3.js uses some weird unicode characters as variable names:
https://github.com/mbostock/d3/blob/91d35b4205d4ef150c61c415b7379404bced7267/d3.js#L1283

Browserify outputs this as

var π = Math.PI, ε = 1e-6, d3_radians = π / 180, d3_degrees = 180 / π;

Which is syntax error.

Terrible practice by d3, but this should not break Browserify.

Most helpful comment

In case this helps anyone in the future: on Windows using powershell (posh git/git shell), redirecting browserify's output with > mucks up utf8 characters. Instead, use -o: browserify [entry files] -o outputfile.js.

All 11 comments

Also ran into this, @substack what piece of the code could this be in?

yeah, this is a real bummer.

Weird, I'm using d3 in one of my projects with browserify and it works just fine

Very strange indeed.
With browserify@latest it is happening to me using browserify as a module. If I bundle the same file via command-line, however, it works fine.

@thlorenz awesome. i can test it out again ;).

What happens when you add charset="utf-8" to your <script> tag? Vanilla d3 seems to have a similar problem.

http://stackoverflow.com/questions/14080401/uncaught-syntaxerror-unexpected-token

:tada: worked like a charm! thanks

@substack was right on the money, in the example I referred to previously I did set charset="utf-8"

The same issue happens if you load the d3 source file directly without setting up meta tags first, so closing this issue because it's a d3 issue, not a browserify issue.

Ha!

In case this helps anyone in the future: on Windows using powershell (posh git/git shell), redirecting browserify's output with > mucks up utf8 characters. Instead, use -o: browserify [entry files] -o outputfile.js.

Was this page helpful?
0 / 5 - 0 ratings