Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer is undefined when using Browserify #147

Closed
felix opened this issue May 24, 2016 · 6 comments
Closed

Buffer is undefined when using Browserify #147

felix opened this issue May 24, 2016 · 6 comments

Comments

@felix
Copy link

felix commented May 24, 2016

When using Browserify v13.0.1 I get an assertion error of Buffer being undefined. It seems commit 4ef34bd as a result of #115 (or #116?) seems to have broken this. It works for me if the require() call is left as this:

Buffer = require('buffer').Buffer;

instead of:

Buffer = require('buf' + 'fer').Buffer;

@indutny
Copy link
Owner

indutny commented May 24, 2016

This is intentional to reduce the size of javascript library. I think you may try to use num.toArrayLike(Buffer, endian, length); in your code to mitigate this.

@felix
Copy link
Author

felix commented May 24, 2016

Ah, you are right. Thank you.

@felix felix closed this as completed May 24, 2016
@indutny
Copy link
Owner

indutny commented May 24, 2016

No problem, glad to help!

paulkernfeld pushed a commit to paulkernfeld/cache-live-stream that referenced this issue Nov 15, 2016
Don't use bn's toBuffer method
See indutny/bn.js#147
@monfera
Copy link

monfera commented Jun 30, 2017

Hello @indutny I've kept running into this for the past year or so and and just skipped the error all the time (basically, all browser reloads which is a lot, and as I'm often in a test runner, Pause On Caught Exceptions must be enabled), but now decided to see what's going on, saw the string concatenation trick and landed here on a search. Too bad I procrastinated as it's one of those dev tool annoyances whose solution was important for me but never urgent :-)

Having read your reply above, I don't entirely follow, how can it reduce the library size if the function would actually be needed? Why include a library otherwise? (I'm definitely missing something.) As it's a very rare practice to trick a module bundler, what's the special circumstance with this library that necessitates it here but not elsewhere? Have you got a link that explains?

yann300 added a commit to yann300/ethereumjs-vm that referenced this issue Aug 1, 2017
here is more details about the issue indutny/bn.js#147
cdetrio pushed a commit to ethereumjs/ethereumjs-monorepo that referenced this issue Aug 1, 2017
here is more details about the issue indutny/bn.js#147
@bj97301
Copy link

bj97301 commented Sep 13, 2017

What about for external dependencies? Is there a way to fake the buffer for them without changing each file?

iantanwx added a commit to Zilliqa/zilliqa-js that referenced this issue Nov 16, 2018
This fixes the failed assertion encountered when using the bundled
instance of bn.js. Refer to indutny/bn.js#147
for a fuller explanation for this workaround.
iantanwx added a commit to Zilliqa/zilliqa-js that referenced this issue Nov 16, 2018
This fixes the failed assertion encountered when using the bundled
instance of bn.js. Refer to indutny/bn.js#147
for a fuller explanation for this workaround.
iantanwx added a commit to Zilliqa/zilliqa-js that referenced this issue Nov 19, 2018
This fixes the failed assertion encountered when using the bundled
instance of bn.js. Refer to indutny/bn.js#147
for a fuller explanation for this workaround.
@mesqueeb
Copy link

mesqueeb commented Mar 27, 2019

I'm having the same problem. Any other way I can achieve this?
new BN('1000000000000000000').toBuffer()
in the browser?

My webpack should polyfill Buffer, but it seems there's a scope problem with bn.js where Buffer is still undefined.

any advice much appreciated!! 😄

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants