Build keeps crashing (Fastify 5 + Prisma Build Failures)
nmn28
PROOP

7 months ago

Railway Deployment Issues - Fastify 5 + Prisma Build Failures

Hey Railway team! We've been struggling with a Fastify + Prisma deployment that keeps failing. Here's our situation:

Project Setup:

Fastify 5 API with Prisma ORM
Node.js 20
Prisma schema located at prisma/schema/schema.prisma (non-standard location)
TypeScript build process
Runtime Issues We've Fixed:

✅ Duplicate @fastify/multipart registration - FSTERRCTPALREADYPRESENT
✅ Fastify 5 Ajv strict mode - FSTERRSCHVALIDATIONBUILD (moved preHandler out of schema)
Docker Build Issues We've Tried to Fix:

  1. ❌ Alpine + Prisma compatibility - Switched from node:18-alpine to node:20-slim for glibc

  2. ❌ Prisma schema path - Added explicit --schema=./prisma/schema/schema.prisma

  3. ❌ Dev dependencies during build - Tried various npm ci configurations

Current Dockerfile (still failing):

FROM node:20-slim
WORKDIR /app

ENV PRISMASKIPGENERATE=true
COPY package*.json ./
RUN npm ci

COPY prisma ./prisma
COPY src ./src
COPY tsconfig.json ./

ENV PRISMASKIPGENERATE=false
RUN npx prisma generate --schema=./prisma/schema/schema.prisma
RUN npm run build
RUN npm prune --production

RUN apt-get update -y && \
apt-get install -y --no-install-recommends openssl && \
apt-get clean && rm -rf /var/lib/apt/lists/*

EXPOSE 3000
CMD ["node","dist/server.js"]

dockerfile

What We've Tried:

Different base images (node:18-alpine, node:20-alpine, node:20-slim)
Various npm ci configurations (--only=production, --omit=dev, full install)
Multiple Prisma generate approaches with/without explicit schema paths
PRISMASKIPGENERATE environment variable manipulation
Different Docker layer ordering strategies
Current Status:
Build is still failing. We suspect there might be Railway-specific build environment issues or we're missing something fundamental about deploying this stack.

Questions:

Are there known issues with Fastify 5 + Prisma on Railway?
Any recommended Dockerfile patterns for this stack?
Could there be build environment differences we should account for?
We've been troubleshooting this extensively and would really appreciate any guidance! 🙏

2 Replies

nmn28
PROOP

7 months ago

n/a


mjablonski
PRO

7 months ago

I guess that Prisma tries to connect via the private network name for your database at build time. This is not possible with Railway. You have to use a public database name at build time.

https://docs.railway.com/guides/private-networking


Loading...