When using randombytes@2.1.0 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
|
const _global = typeof globalThis !== 'undefined' ? globalThis : global |
|
const crypto = _global.crypto || _global.msCrypto |
When using
randombytes@2.1.0in a browser environment with Vite as the build tool, the following error occurs:This error stems from the browser.js implementation attempting to access the
globalobject which is not available in browser DOM environments:As the source code mentioned below
cryptois defined correctlyrandombytes/browser.js
Lines 15 to 16 in b4eb412