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
This commit is contained in:
2025-12-02 13:49:51 +00:00
parent c0358d79d7
commit 3a3db4195f
2 changed files with 7 additions and 18 deletions

View File

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

View File

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