Skip to content
This repository was archived by the owner on Mar 5, 2025. It is now read-only.

isBN breaks in production #1777

Closed
epiqueras opened this issue Jul 13, 2018 · 6 comments · Fixed by #2793
Closed

isBN breaks in production #1777

epiqueras opened this issue Jul 13, 2018 · 6 comments · Fixed by #2793
Assignees
Labels
Bug Addressing a bug

Comments

@epiqueras
Copy link

Minifying the code makes the BN instance's constructor.name !== 'BN' so it breaks web3's implementation of isBN.

@nivida nivida self-assigned this Aug 10, 2018
@nivida nivida added the Bug Addressing a bug label Aug 10, 2018
@nivida
Copy link
Contributor

nivida commented Aug 13, 2018

Hay @epiqueras I've tested it with the minified version of web3 and cant reproduce your case.

Tested with:

var BN = web3.utils.BN;
var bigNumber = new BN(1234);
console.log(web3.utils.isBN(bigNumber));

The result I got:
true

@nivida nivida added more information needed and removed Bug Addressing a bug labels Aug 13, 2018
@loliconer
Copy link

@nivida
There is no problem when using web3.min.js. But error occurs when using webpack to minify code.

import Web3 from 'web3

console.log(Web3.utils.isBN(Web3.utils.toBN(100000000))) // false, because the constructor.name becomes 'o', so 'o' !== 'BN'
console.log(Web3.utils.isBN(new Web3.utils.BN(100000000))) // true

@nivida
Copy link
Contributor

nivida commented Nov 28, 2018

I think it should be solved with the PR #2000

@such
Copy link

such commented Dec 11, 2018

@nivida what makes you think that? I have just looked at the code and isBN still uses constructor.name that causes the issue here. But I'm not a minification expert! Is there anything I'm missing?

@rhlsthrm
Copy link

Ran into this issue in a create-react-app implementation. Googling around I found this: indutny/bn.js#133.

Web3 should use the isBN function from the BN.js library directly.

@nivida nivida added Bug Addressing a bug and removed more information needed labels Apr 15, 2019
@chapati23
Copy link

This is still a problem. Bumping the version of bn.js to 4.11.8 fixed it for me, temporary fix is possible via yarn resolutions, just add the following to your package.json:

  "resolutions": {
    "bn.js": "4.11.8"
  }

@nivida nivida mentioned this issue May 8, 2019
12 tasks
@nivida nivida mentioned this issue May 9, 2019
12 tasks
@nivida nivida mentioned this issue Oct 21, 2019
11 tasks
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Bug Addressing a bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants