skip to Main Content

I have a NodeJS/NestJS project consisting of multiple microservices. I’ve deployed my postgres database and also a microservice pod which interact with the database, on an aws kubernetes cluster. I’m using Prisma as ORM and when I exec into pod and run

npx prisma generate

the output is as below:

Environment variables loaded from .env
Prisma schema loaded from prisma/schema.prisma

✔ Generated Prisma Client (4.6.1 | library) to ./node_modules/@prisma/client in 1.32s
You can now start using Prisma Client in your code. Reference: https://pris.ly/d/client

import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

but when I call an API to create an object in my postgres db by the prisma ORM, I get the error below in the microservice pod:


error:  PrismaClientInitializationError:
Invalid `prisma.session.create()` invocation:


Query engine library for current platform "debian-openssl-1.1.x" could not be found.
You incorrectly pinned it to debian-openssl-1.1.x

This probably happens, because you built Prisma Client on a different platform.
(Prisma Client looked in "/usr/src/app/node_modules/@prisma/client/runtime/libquery_engine-debian-openssl-1.1.x.so.node")

Searched Locations:

  /usr/src/app/node_modules/.prisma/client
  C:UsersMOHSENDesktopcc-gcc-gatewaycc-gatewaydb-managernode_modules@prismaclient
  /usr/src/app/node_modules/@prisma/client
  /usr/src/app/node_modules/.prisma/client
  /usr/src/app/node_modules/.prisma/client
  /tmp/prisma-engines
  /usr/src/app/node_modules/.prisma/client


To solve this problem, add the platform "debian-openssl-1.1.x" to the "binaryTargets" attribute in the "generator" block in the "schema.prisma" file:
generator client {
  provider      = "prisma-client-js"
  binaryTargets = ["native"]
}

Then run "prisma generate" for your changes to take effect.
Read more about deploying Prisma Client: https://pris.ly/d/client-generator
    at RequestHandler.handleRequestError (/usr/src/app/node_modules/@prisma/client/runtime/index.js:34316:13)
    at /usr/src/app/node_modules/@prisma/client/runtime/index.js:34737:25
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async PrismaService._executeRequest (/usr/src/app/node_modules/@prisma/client/runtime/index.js:35301:22)
    at async PrismaService._request (/usr/src/app/node_modules/@prisma/client/runtime/index.js:35273:16)
    at async AppService.createSession (/usr/src/app/dist/app.service.js:28:28) {
  clientVersion: '4.6.1',
  errorCode: undefined
}

Also this is generator client in schema.prisma file:

generator client {
  provider = "prisma-client-js"
  binaryTargets = ["native", "linux-musl", "debian-openssl-1.1.x"]
} 

Before that I had the same problem but the error was mentioning about "linux-musl" like below:

Query engine library for current platform "linux-musl" could not be found.

although I was using linux-musl in the binary target in generator block.

but after lots of research I found that I should not use alpine node in my docker file and instead I used buster and my docker file is as below:

FROM node:buster As development

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install

COPY . .

RUN npm run build db-manager

FROM node:buster as production

WORKDIR /usr/src/app

COPY package*.json ./

RUN npm install 

COPY . .

COPY --from=development /usr/src/app/dist ./dist

CMD ["node", "dist/main"]

I think the problem is that, the prisma query engine could not be found because it is searching wrong locations for platform specific query engine. So, I tried to provide the locations that query engine files are located in my pod, as ENV variables in the deployment file as below:

apiVersion: apps/v1
kind: Deployment
metadata:
  name: db-manager
spec:
  replicas: 3
  selector:
    matchLabels:
      app: db-manager
  template:
    metadata:
      labels:
        app: db-manager
    spec:
      containers:
        - name: db-manager
          image: image-name
          ports:
            - containerPort: 3002
          env:
            - name: PORT
              value: "3002"
            - name: DATABASE_URL
              value: db url
            - name: KAFKA_HOST
              value: kafka url            
            - name: PRISMA_MIGRATION_ENGINE_BINARY
              value: /usr/src/app/node_modules/@prisma/engines/migration-engine-debian-openssl-1.1.x
            - name: PRISMA_INTROSPECTION_ENGINE_BINARY
              value: /usr/src/app/node_modules/@prisma/engines/introspection-engine-debian-openssl-1.1.x
            - name: PRISMA_QUERY_ENGINE_BINARY
              value: /usr/src/app/node_modules/@prisma/engines/libquery_engine-debian-openssl-1.1.x.so.node
            - name: PRISMA_FMT_BINARY
              value: /usr/src/app/node_modules/@prisma/engines/prisma-fmt-debian-openssl-1.1.x

but it doesn’t work and the error still happens when prisma try to execute a create query. I would be very appreciated if anyone could help me. Am I doing something wrong or this is a bug in prisma when used in aws deployment?

thanks for any comments or guides about that.

2

Answers


  1. Try to update to 4.8.0 Prisma version, and set the binaryTargets property in schema.prisma file to:

    (...)
    
    binaryTargets = [
      "native",
      "debian-openssl-1.1.x",
      "debian-openssl-3.0.x",
      "linux-musl",
      "linux-musl-openssl-3.0.x"
    ]
    
    (...)
    

    Don’t forget to run yarn prisma generate

    Login or Signup to reply.
  2. apt-get install -y build-essential libpq-dev
    

    Installing the build-essential and libpq-dev packages helped me. Those support building native dependencies like the pg package that Prisma uses to interact with PostgreSQL databases.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search