Skip to content

Conversation

marcusrein
Copy link
Member

Fix Docker Prisma Query Engine Initialization Error

What was done:

  • Set binaryTargets in schema.prisma to include all needed Linux engines.
  • Updated server build to CommonJS and marked Prisma/Node built-ins as external.
  • Dockerfile now copies the generated Prisma client, engine binaries, and SQLite DB, and sets DATABASE_URL.

How it fixes the issue:

  • Ensures the correct Prisma engine is present in the image.
  • Fixes dynamic require errors at runtime.
  • Server now starts cleanly in Docker with no missing engine or DB errors.

Tested with:

docker build -t hypergraph-test .
docker run --rm -it -p 3030:3030 hypergraph-test

Server boots and Prisma works as expected.

Copy link

vercel bot commented Jun 9, 2025

@marcusrein is attempting to deploy a commit to the The Graph Foundation team on Vercel, but is not a member of this team. To resolve this issue, you can:

  • Make your repository public. Collaboration is free for open source and public repositories.
  • Add @marcusrein as a member. A Pro subscription is required to access Vercel's collaborative features.
    • If you're the owner of the team, click here and add @marcusrein as a member.
    • If you're the user who initiated this build request, click here to request access.
    • If you're already a member of the The Graph Foundation team, make sure that your Vercel account is connected to your GitHub account.

To read more about collaboration on Vercel, click here.

@marcusrein
Copy link
Member Author

New commit:

Fix Docker build: Prisma engine + ESM import errors

What was done

• Kept the server build in pure ESM (no CommonJS switch).
apps/server/tsup.config.ts already marks Prisma / Node built-ins as external.
Prisma import: switched to an explicit file path to avoid Node’s “directory import” error.

// @ts-ignore – generated at build time
import { PrismaClient } from '../generated/client/index.js';

Dockerfile
─ Copies dist/ and apps/server/generated/ so the client + engine binaries are present.
─ Copies dev.db and sets ENV DATABASE_URL=file:./dev.db.
schema.prisma still lists

binaryTargets = ["native", "linux-musl-openssl-3.0.x", "rhel-openssl-3.0.x"]

guaranteeing the correct query-engine binary is generated.

How it fixes the issue

• The generated Prisma client and its engine are now inside the runtime image, so no more PrismaClientInitializationError.
• Explicit import path fixes ERR_UNSUPPORTED_DIR_IMPORT for ESM.
• Server starts cleanly in Docker without missing-module or dynamic-require errors.

Tested with

docker build -t hypergraph-test .
docker run --rm -it -p 3030:3030 hypergraph-test
# → “Listening on port 3030”

All endpoints function as before; the only changes are Docker/runtime-specific.

@nikgraf
Copy link
Collaborator

nikgraf commented Jun 16, 2025

hey @marcusrein, thanks for the PR. I looked a bit more into it and identified that the issue was we have to use the amr64 version. Reduced it to that and fixed it in this PR #220

@nikgraf nikgraf closed this Jun 16, 2025
@nikgraf nikgraf deleted the marcus-debug-docker-build-error branch August 20, 2025 12:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants