Hi there guys, I've been trying to get rid of this...
# orm-help
j
Hi there guys, I've been trying to get rid of this error for days. I am using Next JS, and I am not been able to configure my Prisma client. It doesn't matter what I do or try that I always end with this error. This is the code I am using:
Copy code
import { PrismaClient } from '@prisma/client';

let prisma: PrismaClient;

if (process.env.NODE_ENV === 'production') {
    prisma = new PrismaClient();
} else {
    if (!(global as any).prisma) {
        (global as any).prisma = new PrismaClient();
    }
    prisma = (global as any).prisma;
}

export default prisma;
I've have also tried this:
Copy code
import { PrismaClient } from '@prisma/client';

declare global {
    // allow global `var` declarations
    // eslint-disable-next-line no-var
    var prisma: PrismaClient | undefined;
}

export const prisma =
    global.prisma ||
    new PrismaClient({
        log: ['query'],
    });

if (process.env.NODE_ENV !== 'production') global.prisma = prisma;
This is the error that I am getting:
👀 1
p
Where is this file in your code? Prisma needs to be initialized and leveraged in your server side code. If you import this file at all in your TSX/JSX files that is going to cause this error. In our application we keep this in
lib/server/prisma.ts
and have lint rules to prevent TSX/JSX files from importing anything under
/lib/server
@Javier Sebastián Fernández Happy to help though I don't know how much time I can spare. The first thing to do is trace back a transitive dependency on a TSX file to a flie that imports your prisma.tsx
It's VERY likely you import something in your
server
folder somewhere ELSE in your code; that is then imported by something on your frontend
r
Hi @Javier Sebastián Fernández 👋 Just like Pranav pointed out, importing the server side code in any of your client file will result in this error. You can also enable
DEBUG
mode by following the steps here to get additinal logging output
v
👋 hey @Javier Sebastián Fernández, did you have a chance to try the solutions above? Let us know if this helped!