diff --git a/src/utils/crypto-adapter.ts b/src/utils/crypto-adapter.ts index 1661dba..71a0b90 100644 --- a/src/utils/crypto-adapter.ts +++ b/src/utils/crypto-adapter.ts @@ -17,9 +17,16 @@ function getCrypto(): Crypto { // Node.js environment (15+) - uses Web Crypto API standard if (typeof global !== 'undefined') { - const nodeCrypto = require('crypto'); - if (nodeCrypto.webcrypto) { - return nodeCrypto.webcrypto; + try { + // Note: require() is necessary here for synchronous crypto access in Node.js + // This module is loaded conditionally and esbuild will handle this correctly during bundling + // eslint-disable-next-line @typescript-eslint/no-var-requires + const nodeCrypto = require('crypto') as typeof import('crypto'); + if (nodeCrypto?.webcrypto) { + return nodeCrypto.webcrypto as unknown as Crypto; + } + } catch { + // Crypto module not available or failed to load } } diff --git a/src/utils/encryption-utils.ts b/src/utils/encryption-utils.ts index f729acc..52bcae3 100644 --- a/src/utils/encryption-utils.ts +++ b/src/utils/encryption-utils.ts @@ -8,7 +8,11 @@ interface ElectronSafeStorage { // Safely import safeStorage - may not be available in all environments let safeStorage: ElectronSafeStorage | null = null; try { - const electron = require('electron'); + // Note: require() is necessary here for synchronous access to Electron's safeStorage + // This module is loaded conditionally and may not be available in all environments + // esbuild will handle this correctly during bundling + // eslint-disable-next-line @typescript-eslint/no-var-requires + const electron = require('electron') as typeof import('electron'); safeStorage = electron.safeStorage || null; } catch (error) { console.warn('Electron safeStorage not available, API keys will be stored in plaintext');