Hey all! I’m getting this behavior when trying to query prisma in a
next.js
middleware page. Has anyone encountered this before?
👀 1
n
Necmettin Begiter
03/11/2022, 9:16 AM
You are trying to run the prisma client on the client (browser) side. This is not possible. Prisma runs on the server. This code should be under api/ for a NextJs project.
plus one +1 1
g
Garrett Tolbert
03/11/2022, 4:29 PM
@Necmettin Begiter Doesn’t middleware run on the server though?
n
Necmettin Begiter
03/11/2022, 5:28 PM
As far as I can remember (I don’t use NextJs daily), everything under pages (except api) runs on both server and client. But I’m not an expert on NextJs.
j
Joël
03/14/2022, 8:02 AM
Indeed you can use Prisma only on the server side so these are the options:
getStaticProps = Static Site Generation
getServerSideProps = Server-Side Rendering
API Routes
Standalone Server
See examples at
https://www.prisma.io/nextjs