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>
This commit is contained in:
copilot-swe-agent[bot]
2025-12-27 13:57:46 +00:00
parent 877691ebbe
commit 5491597a79
2 changed files with 14 additions and 9 deletions

View File

@@ -31,10 +31,13 @@ export class S3Storage implements BlobStorage {
private async initializeS3Client(s3Config: NonNullable<BlobStorageConfig['s3']>) {
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,

View File

@@ -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