From 5491597a7968a773e0490cf96efebc567bcbdd1f Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Sat, 27 Dec 2025 13:57:46 +0000 Subject: [PATCH] fix: improve AWS SDK optional import handling - Added @ts-ignore for optional AWS SDK import to prevent TypeScript errors - Changed webpack config to use resolve.fallback instead of externals - Improved error message for missing AWS SDK - Made S3 storage truly optional with better runtime error handling Co-authored-by: johndoe6345789 <224850594+johndoe6345789@users.noreply.github.com> --- dbal/development/src/blob/providers/s3-storage.ts | 11 +++++++---- frontends/nextjs/next.config.ts | 12 +++++++----- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/dbal/development/src/blob/providers/s3-storage.ts b/dbal/development/src/blob/providers/s3-storage.ts index cabc0e7bc..8672dcdfb 100644 --- a/dbal/development/src/blob/providers/s3-storage.ts +++ b/dbal/development/src/blob/providers/s3-storage.ts @@ -31,10 +31,13 @@ export class S3Storage implements BlobStorage { private async initializeS3Client(s3Config: NonNullable) { try { - // Dynamic import to avoid bundling AWS SDK if not needed - const { S3Client } = await import('@aws-sdk/client-s3').catch(() => { - throw new Error('@aws-sdk/client-s3 is not installed. Install it to use S3 storage.') - }) + // Dynamic import to avoid bundling AWS SDK if not installed + // @ts-ignore - Optional dependency + const s3Module = await import('@aws-sdk/client-s3').catch(() => null) + if (!s3Module) { + throw new Error('@aws-sdk/client-s3 is not installed. Install it with: npm install @aws-sdk/client-s3') + } + const { S3Client } = s3Module this.s3Client = new S3Client({ region: s3Config.region, diff --git a/frontends/nextjs/next.config.ts b/frontends/nextjs/next.config.ts index a0f82cbcf..78a59cdd1 100644 --- a/frontends/nextjs/next.config.ts +++ b/frontends/nextjs/next.config.ts @@ -82,17 +82,19 @@ const nextConfig: NextConfig = { NEXT_PUBLIC_DBAL_WS_URL: process.env.DBAL_WS_URL || 'ws://localhost:50051', NEXT_PUBLIC_DBAL_API_KEY: process.env.DBAL_API_KEY || '', }, - webpack(config) { + webpack(config, { isServer }) { config.resolve.alias = { ...config.resolve.alias, '@/dbal': path.resolve(__dirname, '../../dbal/development/src'), '@dbal-ui': path.resolve(__dirname, '../../dbal/shared/ui'), } - // Mark optional dependencies as external to avoid build errors - config.externals = config.externals || [] - if (Array.isArray(config.externals)) { - config.externals.push('@aws-sdk/client-s3') + // Ignore optional AWS SDK on client side + if (!isServer) { + config.resolve.fallback = { + ...config.resolve.fallback, + '@aws-sdk/client-s3': false, + } } return config