Search code examples
node.jsdockerkubernetesprisma

@prisma/client did not initialize yet. Please run "prisma generate" and try to import it again


I am using prisma, postgres, docker, kubernets.

npx prisma migrate dev working.

and npx prisma generate produce below output:

✔ Generated Prisma Client (2.23.0) to ./node_modules/@prisma/client in 68ms
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 tried to use in my route file produce the error:

new-route.ts

import { PrismaClient } from '@prisma/client';

const prisma = new PrismaClient();

my docker file:

FROM node:alpine

WORKDIR /app
COPY package.json .
RUN npm install --only=prod
COPY . .

CMD ["npm", "start"]

Solution

  • I usually don't use docker for this while developing, but I have this issue every time I change something in my schema.prisma and have to use npx prisma generate. The solution for me is to restart the node application running npm start again. Maybe if you restart your containers it might work.

    if you are inside kubernets pod then access the pod using terminal then give generate command

    kubectl exec -it pod_name sh
    npx prisma generate