Skip to content

Buffer being clobbered in capacitor and other non-node environments #255

@schancel

Description

@schancel

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();

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions