Dear friends,
I try to deploy Remix app with Prisma, i used Bun as bundler.
so fly generate Dockerfile for Bun Remix/Prisma template:
# syntax = docker/dockerfile:1
# Adjust BUN_VERSION as desired
ARG BUN_VERSION=1.0.7
FROM oven/bun:${BUN_VERSION} as base
LABEL fly_launch_runtime="Remix/Prisma"
# Remix/Prisma app lives here
WORKDIR /app
# Set production environment
ENV NODE_ENV="production"
# Throw-away build stage to reduce size of final image
FROM base as build
# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install -y build-essential openssl pkg-config python-is-python3
# Install node modules
COPY --link bun.lockb package.json ./
RUN bun install
# Generate Prisma Client
COPY --link prisma .
RUN bunx prisma generate
# Copy application code
COPY --link . .
# Build application
RUN bun run build
# Remove development dependencies
RUN rm -rf node_modules && \
bun install --ci
# Final stage for app image
FROM base
# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y openssl && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Copy built application
COPY --from=build /app /app
# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "bun", "run", "start" ]
but we get this error when run app:
error: Cannot find module ".prisma/client/index" from "/app/node_modules/@prisma/client/index.js"
We use prisma in a Fly app as well. For us, in our build layer of the Dockerfile we run our prisma generate command, then, in the final stage we ensure we copy the generated client across from our node_modules in the build layer.
For example:
FROM node:18-bullseye-slim as base
# initial build steps in build layer ...., there's a prisma generate step in here
FROM base
# other final image steps....
# copy prisma from base build layer
COPY --from=build /workspace/project/node_modules/.prisma /workspace/project/node_modules/.prisma
The prisma generate command by default drops client files into the node_modules folder, so unless you re-run the generate in the final build layer, they would be missing. We are not using bun but it should be pretty much the same.
Hope this helps, or points you in the right direction.
I think the issue may be this line in your Dockerfile:
RUN rm -rf node_modules && \
bun install --ci
In your build layer - you remove the node_modules folder (which the line I gave the example of needs to copy from). If you keep them around in the build layer, you should be able to copy them in the final layer steps.
i tried to ignore remove node_modules but still not found.
# syntax = docker/dockerfile:1
# Adjust BUN_VERSION as desired
ARG BUN_VERSION=1.0.7
FROM oven/bun:${BUN_VERSION} as base
LABEL fly_launch_runtime="Remix/Prisma"
# Remix/Prisma app lives here
WORKDIR /app
# Set production environment
ENV NODE_ENV="production"
# Throw-away build stage to reduce size of final image
FROM base as build
# Install packages needed to build node modules
RUN apt-get update -qq && \
apt-get install -y build-essential openssl pkg-config python-is-python3
# Install node modules
COPY --link bun.lockb package.json ./
RUN bun install
# Generate Prisma Client
COPY --link prisma .
RUN bunx prisma generate
# Copy application code
COPY --link . .
# Build application
RUN bun run build
# COPY /app/node_modules/.prisma /app/.prisma
# Remove development dependencies
# RUN rm -rf node_modules && \
# bun install --ci
# Final stage for app image
FROM base
# Install packages needed for deployment
RUN apt-get update -qq && \
apt-get install --no-install-recommends -y openssl && \
rm -rf /var/lib/apt/lists /var/cache/apt/archives
# Copy built application
COPY --from=build /app /app
COPY --from=build /app/node_modules/.prisma /app/node_modules/.prisma
# Start the server by default, this can be overwritten at runtime
EXPOSE 3000
CMD [ "bun", "run", "start" ]