Bitcoinjs-lib: Issue when using browserify instructions on bitcoinjs.org

Created on 23 Sep 2017  Â·  14Comments  Â·  Source: bitcoinjs/bitcoinjs-lib

I used the compile for browser instructions on bitcoinjs.org

and the follow error was shown

`as-MacBook-Pro:test a$ sudo npm install -g browserify uglify-js
/usr/local/bin/uglifyjs -> /usr/local/lib/node_modules/uglify-js/bin/uglifyjs
/usr/local/bin/browserify -> /usr/local/lib/node_modules/browserify/bin/cmd.js

  • [email protected]
  • [email protected]
    added 135 packages in 8.086s
    as-MacBook-Pro:test a$ browserify -r bitcoinjs-lib -s bitcoin | uglifyjs > bitcoinjs.min.js
    Parse error at 0:96,4
    let ALPHABET = 'qpzry9x8gf2tvdw0s3jn54khce6mua7l'
    ^
    ERROR: Unexpected token: name (ALPHABET)
    at JS_Parse_Error.get (eval at (/usr/local/lib/node_modules/uglify-js/tools/node.js:21:1), :79:23)
    at fatal (/usr/local/lib/node_modules/uglify-js/bin/uglifyjs:268:52)
    at run (/usr/local/lib/node_modules/uglify-js/bin/uglifyjs:225:9)
    at Socket. (/usr/local/lib/node_modules/uglify-js/bin/uglifyjs:163:9)
    at emitNone (events.js:110:20)
    at Socket.emit (events.js:207:7)
    at endReadableNT (_stream_readable.js:1047:12)
    at _combinedTickCallback (internal/process/next_tick.js:102:11)
    at process._tickCallback (internal/process/next_tick.js:161:9)`
how to / question / docs

Most helpful comment

Hey Christian.

What version of node are you using? Try switching nvm to use v7

All 14 comments

Hey Christian.

What version of node are you using? Try switching nvm to use v7

seems my handle gave me away
node version is v8.1.2

I think the issue has something to do with
https://github.com/bitcoinjs/bech32/blob/master/index.js

maybe it doesnt like let?

@mandelmonkey it appears that uglify-js doesn't support ES6 let statements.
In repository, we track LTS node versions for tracking backwards compatibility.

Maybe use --transform [ babelify ] on your browserify build step to downgrade to ES5.

I think this should be something we outline in the README, with steps.
Thoughts @bitcoinjs/committers ?

This decision would also mean we can upgrade the repository to use let instead of var throughout.
Will update README in a PR for discussion...

I agree. Let’s. ;-)

Closing in favour of #903

thanks I managed to browserify using the github readme instructions
https://github.com/bitcoinjs/bitcoinjs-lib#browser

@mandelmonkey was #903 helpful?

Yes thank you!

On Mon, Sep 25, 2017 at 3:22 PM, Daniel Cousens notifications@github.com
wrote:

@mandelmonkey https://github.com/mandelmonkey was #903
https://github.com/bitcoinjs/bitcoinjs-lib/pull/903 helpful
?

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/bitcoinjs/bitcoinjs-lib/issues/902#issuecomment-331787484,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AGRBNwPlc7tX35RkvrRL3cg-fmuA5O6fks5sl0a_gaJpZM4Pheo8
.

Hey @mandelmonkey would you mind sharing what you did to get yours running? I'm still having that issue with the bech32 lib not compiling to es5.

My script is browserify src/index.js --transform [ babelify --presets [ env ] ] --standalone bitcoinjs-lib > bin/bitcoinjs-lib.js

I must be missing something!

EDIT: I got it to work for now by making it a global transform.

EDIT: I got it to work for now by making it a global transform.

can you elaborate?

@tweeres04 I know that if your node version is too low it wouldn't support the 'let'

@dcousens @mandelmonkey It looks like by default browserify transforms only apply to files at or below the directory level of the entry file. The bech32 library (the one in es6 that was causing me problems) is one level up (at ./node_modules/bech32) from BitcoinJS's ./src/index.js, so by adding the --global flag to my transform I was able to get it to compile.

For those who encounter this issue, my full script for compiling is browserify src/index.js --t [ babelify --global --presets [ env ] ] --standalone bitcoinjs-lib | uglifyjs --compress --mangle reserved=['BigInteger,ECPair,Point'] > bin/bitcoinjs-lib.min.js

Ah, you are doing a --standalone compilation, that explains it, my bad I didn't see that in your OP.

I suspect many users are not doing --standalone, but simply using browserify at the top of their stack.

Right. Yeah I have an existing project with webpack so I'm compiling just BitcoinJS with browserify.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

Beardcoding picture Beardcoding  Â·  3Comments

namnv04 picture namnv04  Â·  3Comments

ghost picture ghost  Â·  3Comments

yakitorifoodie picture yakitorifoodie  Â·  3Comments

hoshsadiq picture hoshsadiq  Â·  3Comments