Error with Remix/Prisma with Bun Dockerfile

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"

i donā€™t known what wrong. please help !

My best guess is that prisma is listed as a devDependency in your package.json.

See: Dependencies Ā· Fly Docs

1 Like

install package @prisma/client

npm i @prisma/client

1 Like

this is my package.json, it already have ā€˜prismaā€™ in devDependency but still not work.

{
  "name": "demo",
  "private": true,
  "sideEffects": false,
  "type": "module",
  "scripts": {
    "build": "remix build",
    "dev": "remix dev --manual",
    "start": "remix-serve ./build/index.js",
    "typecheck": "tsc"
  },
  "dependencies": {
    "@prisma/client": "5.5.2",
    "@remix-run/css-bundle": "^2.1.0",
    "@remix-run/node": "^2.1.0",
    "@remix-run/react": "^2.1.0",
    "@remix-run/serve": "^2.1.0",
    "isbot": "^3.6.8",
    "react": "^18.2.0",
    "react-dom": "^18.2.0"
  },
  "devDependencies": {
    "@flydotio/dockerfile": "latest",
    "@remix-run/dev": "^2.1.0",
    "@remix-run/eslint-config": "^2.1.0",
    "@types/react": "^18.2.20",
    "@types/react-dom": "^18.2.7",
    "eslint": "^8.38.0",
    "prisma": "5.5.2",
    "typescript": "^5.1.6"
  },
  "engines": {
    "node": ">=18.0.0"
  }
}

Hi there,

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.

1 Like

Thatā€™s probably not what you want. A devDependency is only available in development, not in production.

thank @davew i try to apply to Dockerfile with this command:

COPY --from=build /app/node_modules/.prisma /app/node_modules/.prisma

But error not found. >.<ā€™

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.

1 Like

I encourage everybody to read that page I wrote on this topic, it shows two different ways to fix this problem:

1 Like

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" ]

dear friends, we have any solution for this ?
i tried many way to make remix, bun and prisma can deploy to fly.io, but unsuccessful for now

Iā€™m not up to date on the status of remix/bun support. Hereā€™s what I know:

But I did try GitHub - remix-run/indie-stack: The Remix Stack for deploying to Fly with SQLite, authentication, testing, linting, formatting, etc. - substituting bunx for npx, then running rm fly.toml Dockerfile .dockerignore before running fly launch, and while the app did build, it failed to start:

[info]/usr/bin/env: 'node': No such file or directory

Digging a bit deeper, I see:

% head -1 ./node_modules/.bin/remix-serve
#!/usr/bin/env node

Without having an example/demo remix/bun/prisma app to play with, Iā€™m at a loss at how to help you further.

1 Like

Thanks for your support
i create a demo with issues:

Thanks! I tried the demo:

  • fly launch builds an image successfully
  • fly deploy fails to start with the message error: Cannot find module ".prisma/client/index" from "/app/node_modules/@prisma/client/index.js"

At this point I run fly console which lets me explore the image. From there, I run bunx prisma generate, and get:

  šŸ” Resolving [1/1]

On a hunch, I return to my laptop, and run:

rm bun.lockb
npm install
npx dockerfile

I also replace bunx with npx in fly.toml. Then I run fly deploy, and the deploy succeeds.

So the remaining question is: why does bunx prisma generate fail when npx prisma generate succeeds? Your prisma/schema.prisma is very straightforward.

I found this: Bun: Can't `prisma generate` on Docker Ā· Issue #21241 Ā· prisma/prisma Ā· GitHub

1 Like

thanks @rubys i found this related too: Bun doesn't run prisma generate or prisma migrate inside docker containers or WSL Ā· Issue #5320 Ā· oven-sh/bun Ā· GitHub

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.