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 being clobbered in capacitor and other non-node environments #255

Closed
schancel opened this issue Dec 1, 2020 · 1 comment
Closed

Comments

@schancel
Copy link

schancel commented Dec 1, 2020

https://github.com/indutny/bn.js/blob/master/lib/bn.js#L51-L55

Buffer will already be defined, and require() simply returns an empty object in Capacitor. This results in Buffer being reset to undefined and triggering asserts later on. Not sure what the best course of action is here due to variable lifetimes.

Maybe:

const tryPolyfillBuffer = () => {
  if(typeof Buffer !== 'function') {
    try {
      return require('buffer').Buffer;
    } catch (err) {
      return Buffer;
    }
  }
  return Buffer;
}

let Buffer = tryPolyfillBuffer();
@fanatid
Copy link
Collaborator

fanatid commented Feb 23, 2021

Closed in #260

@fanatid fanatid closed this as completed Feb 23, 2021
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

2 participants