randombytes icon indicating copy to clipboard operation
randombytes copied to clipboard

`global` Reference Error in Browser Environment

Open 0xharshrastogi opened this issue 1 year ago • 0 comments

When using [email protected] in a browser environment with Vite as the build tool, the following error occurs:

Uncaught ReferenceError: global is not defined

This error stems from the browser.js implementation attempting to access the global object which is not available in browser DOM environments:

var Buffer = require('safe-buffer').Buffer
var crypto = global.crypto || global.msCrypto

As the source code mentioned below crypto is defined correctly

https://github.com/browserify/randombytes/blob/b4eb4126fccc503e375853ca7b3e96aaa34af9e6/browser.js#L15-L16

0xharshrastogi avatar Nov 13 '24 02:11 0xharshrastogi