question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Problem with webpack (UglifyJS) and version bitcoinjs-lib@3.1.1

See original GitHub issue

I have a project using a Webpack boilerplate (https://github.com/Josema/preact-webpack-hmr) that has two environments. dev and prod. On dev, I don’t have any issue because Webpack does not Uglify the code. But in prod I have this problem:

u {message: "Expected property "1" of type BigInteger, got n", __label: undefined, __property: 1, __value: n, __type: ƒ, …}message: "Expected property "1" of type BigInteger, got n"__label: undefined__property: 1__type: ƒ t(t)__value: n {0: 39560396, 1: 24254232, 2: 47726532, 3: 54351623, 4: 24134563, 5: 20729478, 6: 48965898, 7: 65576818, 8: 4252187, 9: 3018492, 10: 0, t: 10, s: 0}__valueTypeName: "n"stack: "Error: Expected property "1" of type BigInteger, got n↵    at d (http://localhost:8000/static/bundle/libs.js:13:92640)↵    at http://localhost:8000/static/bundle/libs.js:7:49765↵    at Array.every (<anonymous>)↵    at e (http://localhost:8000/static/bundle/libs.js:7:49707)↵    at i (http://localhost:8000/static/bundle/libs.js:7:48167)↵    at Object.i [as sign] (http://localhost:8000/static/bundle/libs.js:25:35134)↵    at n.sign (http://localhost:8000/static/bundle/libs.js:13:61402)↵    at http://localhost:8000/static/bundle/libs.js:25:55722↵    at Array.some (<anonymous>)↵    at d.sign (http://localhost:8000/static/bundle/libs.js:25:55590)"__proto__: Errorconstructor: ƒ f(e,t,r)__proto__: Object
(anonymous) @ main.js:1
Promise rejected (async)
value @ main.js:1
S @ libs.js:13

I know the error comes from bitcoinjs-lib because happen when I use the TransactionBuilder.sign() method.

Then, if I upgrade to 3.2.1 or above the problem of the code disappear. And I got this error when running Webpack/Uglify.

Output when using @3.1.1:

> webpack --config=./webpack/production.js --optimize-minimize --progress --colors --display-error-details

Hash: f39c6260afc7aeb5b9fe
Version: webpack 3.4.1
Time: 43029ms
  Asset    Size  Chunks                    Chunk Names
main.js  248 kB       0  [emitted]         main
libs.js  578 kB       1  [emitted]  [big]  libs
  [14] ./src/api/crypto.js 5.64 kB {0} [built]
  [15] (webpack)/buildin/global.js 509 bytes {1} [built]
  [19] ./src/api/numbers.js 1.71 kB {0} [built]
  [23] ./src/api/Coins/ETH.js 6.13 kB {0} [built]
 [119] multi ./src/index.js 28 bytes {0} [built]
 [120] ./src/index.js + 88 modules 525 kB {0} [built]
 [201] (webpack)/buildin/module.js 517 bytes {1} [built]
    + 273 hidden modules

All good. Output when using @3.2.1 or above:

> webpack --config=./webpack/production.js --optimize-minimize --progress --colors --display-error-details

Hash: cb0937ec69d6fb04ecff
Version: webpack 3.4.1
Time: 17002ms
  Asset     Size  Chunks                    Chunk Names
main.js   248 kB       0  [emitted]         main
libs.js  1.32 MB       1  [emitted]  [big]  libs
  [14] ./src/api/crypto.js 5.64 kB {0} [built]
  [15] (webpack)/buildin/global.js 509 bytes {1} [built]
  [19] ./src/api/numbers.js 1.71 kB {0} [built]
  [23] ./src/api/Coins/ETH.js 6.13 kB {0} [built]
 [124] multi ./src/index.js 28 bytes {0} [built]
 [125] ./src/index.js + 88 modules 525 kB {0} [built]
 [202] (webpack)/buildin/module.js 517 bytes {1} [built]
    + 274 hidden modules

ERROR in libs.js from UglifyJs
Unexpected token: name (ALPHABET) [libs.js:32162,4]

ERROR in libs.js from UglifyJs
Unexpected token: name (ALPHABET) [libs.js:32162,4]
npm ERR! code ELIFECYCLE
npm ERR! errno 2
npm ERR! coinfy@1.0.0 build: `webpack --config=./webpack/production.js --optimize-minimize --progress --colors --display-error-details`
npm ERR! Exit status 2
npm ERR!
npm ERR! Failed at the coinfy@1.0.0 build script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /Users/enzo/.npm/_logs/2017-12-11T16_28_14_841Z-debug.log

Notice that the size of libs.js change from 578 kB to 1.32 MB. I don’t know how to fix this so any help would be really really appreciated.

I have created a repository with the minimal configuration to reproduce the same errors: https://github.com/Josema/bitcoinjs-lib_error

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:13 (5 by maintainers)

github_iconTop GitHub Comments

9reactions
Josemacommented, Dec 12, 2017

Wow, that fixed the issue!

For webpack users just add the options inside of plugins UglifyEsPlugin

new UglifyEsPlugin({
    mangle: {
        reserved: [
            'Buffer',
            'BigInteger',
            'Point',
            'ECPubKey',
            'ECKey',
            'sha512_asm',
            'asm',
            'ECPair',
            'HDNode'
        ]
    }
})

Thank you @afk11. Thank you all too.

4reactions
afk11commented, Dec 12, 2017
Read more comments on GitHub >

github_iconTop Results From Across the Web

uglifyjs-webpack-plugin cannot uglify any file #220 - GitHub
I used es7, es6, if i use webpack.optimize.UglifyJsPlugin , it can work normally. "uglifyjs-webpack-plugin": "^1.1.8", "webpack" ...
Read more >
ERROR in bundle.js from UglifyJs - javascript - Stack Overflow
UglifyJS WebPack plugin. If you want to control the version of webpack plugin, you must install and use it explicitly as well.
Read more >
uglifyjs-webpack-plugin - npm
UglifyJS plugin for webpack. Latest version: 2.2.0, last published: 3 years ago. Start using uglifyjs-webpack-plugin in your project by ...
Read more >
uglifyjs-webpack-plugin - npm.io
Useful for using and testing unpublished versions or forks. ⚠️ Always use require inside minify function when parallel option enabled. webpack.config.js
Read more >
uglifyjs-webpack-plugin/package.json - UNPKG
1, {. 2, "name": "uglifyjs-webpack-plugin",. 3, "version": "2.2.0",. 4, "description": "UglifyJS plugin for webpack",. 5, "license": "MIT",.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found