From 3a3db4195f63cc49fdcbb6da7be3002ce5e041d5 Mon Sep 17 00:00:00 2001 From: Paul Bailey Date: Tue, 2 Dec 2025 13:49:51 +0000 Subject: [PATCH] Fix Docker Prisma constructor error - Remove --ignore-scripts from npm ci in builder stage - Simplify Prisma client initialization - Ensure proper file copying order in Docker - Remove async connection handling that may cause issues --- Dockerfile | 11 +++++++---- lib/db.ts | 14 -------------- 2 files changed, 7 insertions(+), 18 deletions(-) diff --git a/Dockerfile b/Dockerfile index 38292af..7953530 100644 --- a/Dockerfile +++ b/Dockerfile @@ -18,7 +18,7 @@ WORKDIR /app # Copy package files and install all dependencies (including dev) COPY package.json package-lock.json* ./ -RUN npm ci --ignore-scripts +RUN npm ci # Copy source code COPY . . @@ -29,6 +29,7 @@ RUN npx prisma generate # Build Next.js application ENV NEXT_TELEMETRY_DISABLED=1 ENV AUTH_TRUST_HOST=true +ENV NODE_ENV=production RUN npm run build # Production image, copy all the files and run next @@ -42,13 +43,15 @@ ENV NEXT_TELEMETRY_DISABLED=1 RUN addgroup --system --gid 1001 nodejs RUN adduser --system --uid 1001 nextjs -# Copy necessary files -COPY --from=builder --chown=nextjs:nodejs /app/public ./public +# Copy the standalone output COPY --from=builder --chown=nextjs:nodejs /app/.next/standalone ./ COPY --from=builder --chown=nextjs:nodejs /app/.next/static ./.next/static +COPY --from=builder --chown=nextjs:nodejs /app/public ./public + +# Copy Prisma files +COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma COPY --from=builder --chown=nextjs:nodejs /app/node_modules/.prisma ./node_modules/.prisma COPY --from=builder --chown=nextjs:nodejs /app/node_modules/@prisma ./node_modules/@prisma -COPY --from=builder --chown=nextjs:nodejs /app/prisma ./prisma USER nextjs diff --git a/lib/db.ts b/lib/db.ts index 4af4f8b..dbea5a5 100644 --- a/lib/db.ts +++ b/lib/db.ts @@ -4,22 +4,8 @@ const globalForPrisma = globalThis as unknown as { prisma: PrismaClient | undefined } -// Create Prisma client with connection error handling export const prisma = globalForPrisma.prisma ?? new PrismaClient({ log: process.env.NODE_ENV === 'development' ? ['error', 'warn'] : ['error'], }) -// Handle connection errors -prisma.$connect().catch((error) => { - console.error('Failed to connect to database:', error) - // Don't throw here - let individual queries handle connection errors -}) - -// Graceful shutdown -if (typeof window === 'undefined') { - process.on('beforeExit', async () => { - await prisma.$disconnect() - }) -} - if (process.env.NODE_ENV !== 'production') globalForPrisma.prisma = prisma \ No newline at end of file