Skip to content

global is replaced by globalThis? #29

Closed

Description

@garmin21

There is a problem with the global reference used in the source code, it may not exist, because it is a compatibility problem, why not use globalThis?

Activity

  1. justin0mcateer commented on Nov 8, 2022

    @justin0mcateer

    I ran into this problem and needed to patch the package due to lack of 'global' in the browser environment.

    Here is the (hack) patch I used:

    diff --git a/node_modules/randombytes/browser.js b/node_modules/randombytes/browser.js
    index 0fb0b71..7dc0e6c 100644
    --- a/node_modules/randombytes/browser.js
    +++ b/node_modules/randombytes/browser.js
    @@ -13,7 +13,9 @@ function oldBrowser () {
     }
     
     var Buffer = require('safe-buffer').Buffer
    -var crypto = global.crypto || global.msCrypto
    +// var crypto = global.crypto || global.msCrypto
    +var crypto = globalThis.crypto || globalThis.msCrypto
    +
     
     if (crypto && crypto.getRandomValues) {
       module.exports = randomBytes
  2. added a commit that references this issue on Jan 8, 2023
    b160e82
  3. bneijt commented on Jan 9, 2023

    @bneijt
    Contributor

    I think it makes sense to use globalThis if available and fall back to the injected global if required, so I created a PR to that effect.

  4. added a commit that references this issue on Jul 26, 2023
    b4eb412
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions