Need to clarify where to import Prisma from
In the past the prisma client was generated inside
node_modules. So I always imported everything from @prisma/client.
But now since the Prisma Client is generated in a custom path outside node_modules I should be importing it like this right? I am using Next.js and according to this page I create the Prisma Client instance like below. This is the correct way right? Instead of importing the PrismaClient from @prisma/client like we did in the past now I import it from the generated output?
If the above is correct, then I will be simply importing prisma from this file like below.
But assume I want to use the Prisma namespace, in order to check an error instance. Like described here: https://www.prisma.io/docs/orm/prisma-client/debugging-and-troubleshooting/handling-exceptions-and-errors
Then should I be importing that also from ../generated/prisma? Or from @prisma/client? I tried both, and both seem to import something without any issues. So I am not sure what to use. I don't really have a good understanding what happens under the hood of these so I am a bit confused when to use what.4 Replies
You chose to debug with a human. They'll tinker with your query soon. If you get curious meanwhile, hop into
#ask-ai for a quick spin!Hey!
If you are generating PrismaClient at a custom location then you should be importing it from the custom location, always! You shouldn't import from
node_modulesThanks for the response.
Yeah I do import the
PrismaClient from the generated output but was bit confused should I do the same for Prisma as well. But I guess it does makes sense to import everything from the generated output.Yes, you should import Prisma from generated output as well.