mirror of
https://github.com/johndoe6345789/metabuilder.git
synced 2026-04-24 13:54:57 +00:00
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:
@@ -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,
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user