randombytes: Replace run-time require detection

Using require() as an expression leads to compile errors in webpack.
This issue can be solved by guarding the use of require by the 'correct'
run-time check using `typeof require`.
This commit is contained in:
Arne Goedeke 2023-03-02 09:48:16 +01:00
parent ae2df3305e
commit f93d546ee0

View File

@ -20,7 +20,7 @@ var randombytes = (function () {
if (crypto && crypto.getRandomValues) return browserBytes if (crypto && crypto.getRandomValues) return browserBytes
if (require != null) { if (typeof require === 'function') {
// Node.js. Bust Browserify // Node.js. Bust Browserify
crypto = require('cry' + 'pto') crypto = require('cry' + 'pto')
if (crypto && crypto.randomBytes) return nodeBytes if (crypto && crypto.randomBytes) return nodeBytes