DEV Community

Bilal Niaz
Bilal Niaz

Posted on

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

This error is very common with Prisma, and it means the Prisma Client was not generated

First, check if both required Prisma packages are properly installed in your project:

npm ls @prisma/client prisma
Enter fullscreen mode Exit fullscreen mode

You should see both packages listed. If either is missing, install them:

npm install @prisma/client
npm install prisma --save-dev
Enter fullscreen mode Exit fullscreen mode

Why both packages?

  • @prisma/client - The runtime client you import in your code
  • Prisma: The CLI tool used for migrations and generating the client

Prisma requires a schema file at a specific location. Check that you have a file at:

your-project/
├── prisma/
│ └── schema.prisma
├── node_modules/
├── package.json
└── index.js

Your schema.prisma file must contain the client generator configuration:

generator client {
provider = "prisma-client-js"
}

If you don't have this file, initialize Prisma:

npx prisma init
Enter fullscreen mode Exit fullscreen mode

Run migration (recommended).

npx prisma migrate dev --name init
Enter fullscreen mode Exit fullscreen mode

This is where many developers make mistakes. Ensure you're importing Prisma Client correctly in your code

Correct:

const { PrismaClient } = require('@prisma/client');
const prisma = new PrismaClient();

Top comments (0)