prisma / blogr-nextjs-prisma

111 stars 83 forks source link

PrismaClient is unable to be run in the browser. #21

Open Jawmo opened 2 years ago

Jawmo commented 2 years ago

"PrismaClient is unable to be run in the browser."

Any idea why i might be seeing this? Project following this tutorial: https://vercel.com/guides/nextjs-prisma-postgres

Loading the index page produces the error. Commenting out getStaticProps removes it.

Here is my pages/index.tsx:

import { Home } from "src/pages/home";
import prisma from "lib/prisma";
import { GetStaticProps } from "next";

const getStaticProps: GetStaticProps = async () => {
  const users = await prisma.user.findMany({});
  return { props: { users } };
};

export default Home;

This will correct it, however I feel like the separated component is a better quality setup:

import { PrismaClient } from "@prisma/client";
import { GetStaticProps } from "next";

const getStaticProps: GetStaticProps = async () => {
  const prisma = new PrismaClient();
  const users = await prisma.user.findMany({});
  return { props: { users } };
};