File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -41,10 +41,18 @@ let subtleCrypto = globalThis.crypto?.subtle;
4141
4242async function ensureSubtleCryptoExists ( ) {
4343 if ( ! subtleCrypto ) {
44- if ( globalThis . require ) {
45- subtleCrypto = globalThis . require ( 'node:crypto' ) ?. webcrypto ?. subtle ;
46- } else {
47- subtleCrypto = ( await import ( 'node:crypto' ) ) ?. webcrypto ?. subtle as SubtleCrypto ;
44+ try {
45+ // eslint-disable-next-line @typescript-eslint/no-require-imports, global-require -- Backward compatibility for Node.js versions < 19
46+ subtleCrypto = require ( 'node:crypto' ) ?. webcrypto ?. subtle ;
47+ if ( subtleCrypto ) return ;
48+ } catch {
49+ // Ignore require error
50+ }
51+
52+ try {
53+ subtleCrypto = ( await import ( 'node:crypto' ) ) . webcrypto . subtle as SubtleCrypto ;
54+ } catch {
55+ // Ignore import error
4856 }
4957
5058 if ( ! subtleCrypto ) {
You can’t perform that action at this time.
0 commit comments