Why do I have both `@prisma/client` and `generated/prisma/client` in my import suggestions?
Hello,
first off the docs say:
"The install command invokes prisma generate for you which reads your Prisma schema and generates a version of Prisma Client that is tailored to your models."
This was not true for me, when I ran
npm i @prisma/client
, the prisma generate command was not run, I had to run it manually. Second when I try to import stuff from the client, I keep getting suggestions from both @prisma/client
and my generated client, it's causing a lot of confusion. Is this normal and can I use them interchangebly?1 Reply
You opted for speed from this bot. Let's conjure up an answer right now!
You're experiencing a common confusion with Prisma Client imports. Let me address your questions:
About
npm install @prisma/client
not running prisma generate
You're right that the documentation states the install command should invoke prisma generate
automatically. However, this behavior can be inconsistent, as evidenced by your experience and a known issue in Prisma. In some versions, installing @prisma/client
doesn't automatically generate the client code, requiring you to run npx prisma generate
manually as mentioned in this GitHub issue.
About seeing both @prisma/client
and generated/prisma/client
in import suggestions
This is related to how Prisma Client is structured. The @prisma/client
package consists of two key parts:
1. The @prisma/client
module itself
2. The generated client code (typically in .prisma/client
by default)
According to the documentation, @prisma/client/index.d.ts
exports the generated client:
This means you should import from @prisma/client
in your code:
The Prisma documentation explains this structure.
Why you're seeing a different path
It appears you have a custom output path configured in your schema.prisma file (to generated/prisma/client
instead of the default .prisma/client
). This can be done by setting the output
parameter in your generator block:
Can you use them interchangeably?
In theory, you should only use the imports from @prisma/client
as it's designed to properly export the generated client. Using direct imports from your generated client location might work but could lead to issues wit
h future updates or in different environments.
For consistency and to follow best practices, stick with importing from @prisma/client
.
GitHub issues suggest that some import problems can be resolved by:
1. Reloading your IDE window
2. Making sure you don't have path aliases in your tsconfig.json that conflict with @prisma
3. Running prisma generate
after any schema changes
Hope this helps clarify the situation!
✅ Great, thanks for letting us know that this solved your question!