Attempting to retrieve user information based on the current session, I created a small _middleware.ts file. In order to get the users' data, I imported a prisma (ORM) client. However, upon loading the page in the browser, an error message appeared:
Error: PrismaClient is unable to be run in the browser.
I was under the impression that the _middleware would only run in the browser, so I'm surprised that it's being sent to the client as well.
Is there a way to address or prevent this issue from occurring?
Edit:
One potential solution I came across involves configuring webpack to exclude the "middleware" from the front-end bundle. However, this feels like a workaround and may introduce other bugs.
Edit2:
In my research, I also discovered the following command in next.js:
// Errors from the middleware are reported as client-side errors
// since the middleware is compiled using the client compiler
Could the use of the client compiler for compilation be causing the problem?