From: Chris Duncan Date: Tue, 26 Nov 2024 05:46:54 +0000 (-0800) Subject: Add try-catch block to avoid esbuild warnings when building for browser. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=1b4078ef0ed9bb4c8f0242d9c9c0a30617717407;p=libnemo.git Add try-catch block to avoid esbuild warnings when building for browser. --- diff --git a/src/lib/workers/nacl-nano.ts b/src/lib/workers/nacl-nano.ts index 7bac240..f800f94 100644 --- a/src/lib/workers/nacl-nano.ts +++ b/src/lib/workers/nacl-nano.ts @@ -866,13 +866,17 @@ const setPRNG = function(fn) { }); } else if (typeof require !== 'undefined') { // Node.js. - crypto = require('crypto'); - if (crypto && crypto.randomBytes) { - setPRNG(function(x, n) { - var i, v = crypto.randomBytes(n); - for (i = 0; i < n; i++) x[i] = v[i]; - cleanup(v); - }); + try { + crypto = require('node:crypto'); + if (crypto && crypto.randomBytes) { + setPRNG(function(x, n) { + var i, v = crypto.randomBytes(n); + for (i = 0; i < n; i++) x[i] = v[i]; + cleanup(v); + }); + } + } catch (err) { + throw new Error('failed to load node:crypto') } } })();