Next.js Discord

Discord Forum

PrismaClient Vercel

Unanswered
Sun bear posted this in #help-forum
Open in Discord
Sun bearOP
Migrated postgres db from AWS RDS to Vercel hosting.
Getting this error:
ReferenceError: PrismaClient is not defined
    at /var/task/.next/server/pages/api/entities/[id]/fillings/[fid].js:167:16
Error: Runtime exited with error: exit status 1
Runtime.ExitError

I am instantiating PrismaClient with global object. The import was working with AWS and it has not changed.

import prisma from '@/lib/server/prisma'

Here is the declaration
import { PrismaClient } from '@prisma/client'
declare global {
    var prisma: PrismaClient | undefined
}

// PrismaClient is attached to the `global` object in development to prevent
// exhausting your database connection limit.
//
// Learn more:
// https://pris.ly/d/help/next-js-best-practices

const prisma = global.prisma || new PrismaClient({ log: ['info'] })
if (process.env.NODE_ENV !== 'production') global.prisma = prisma

// let prisma: PrismaClient

// if (process.env.NODE_ENV === 'production') {
//     prisma = new PrismaClient()
// } else {
//     if (!global.prisma) {
//         global.prisma = new PrismaClient()
//     }
//     prisma = global.prisma
// }
export default prisma

So far I've tried adding the post install script
"postinstall": "prisma generate"

Ive also tried moving the prisma client package from devDependencies to dependencies.
Tried altering the build script, here is my current:
"build": "next build && prisma generate",
"vercel-build": "prisma generate && prisma db push && prisma db seed && next build",


Thanks in advance.

7 Replies

Sun bearOP
bump
Sun bearOP
Bump
Sun bearOP
bump
@Sun bear Migrated postgres db from AWS RDS to Vercel hosting. Getting this error: ReferenceError: PrismaClient is not defined at /var/task/.next/server/pages/api/entities/[id]/fillings/[fid].js:167:16 Error: Runtime exited with error: exit status 1 Runtime.ExitError I am instantiating PrismaClient with global object. The import was working with AWS and it has not changed. typescript import prisma from '@/lib/server/prisma' Here is the declaration typescript import { PrismaClient } from '@prisma/client' declare global { var prisma: PrismaClient | undefined } // PrismaClient is attached to the `global` object in development to prevent // exhausting your database connection limit. // // Learn more: // https://pris.ly/d/help/next-js-best-practices const prisma = global.prisma || new PrismaClient({ log: ['info'] }) if (process.env.NODE_ENV !== 'production') global.prisma = prisma // let prisma: PrismaClient // if (process.env.NODE_ENV === 'production') { // prisma = new PrismaClient() // } else { // if (!global.prisma) { // global.prisma = new PrismaClient() // } // prisma = global.prisma // } export default prisma So far I've tried adding the post install script "postinstall": "prisma generate" Ive also tried moving the prisma client package from devDependencies to dependencies. Tried altering the build script, here is my current: "build": "next build && prisma generate", "vercel-build": "prisma generate && prisma db push && prisma db seed && next build", Thanks in advance.
Cuvier’s Dwarf Caiman
You can try putting ‘prisma generate’ before ‘next build’ in you package.json’s build script. So ‘“build”: “prisma generate && next build”’
And I think you should also change the vercel-build. You could try putting “prisma generate” after “prisma db seed” (and before “next build”)
@Sun bear Thanks. No luck unfortunately. Any more ideas I can try?
Cuvier’s Dwarf Caiman
Other than your prisma db declaration I use the exact same methods.
You could try the one I use, but I would it weird if it would solve your problem.
Here is it anyway

‘’’
import { PrismaClient } from "@prisma/client";

declare global {
var prisma: PrismaClient | undefined;
}

const client = globalThis.prisma || new PrismaClient();
if (process.env.NODE_ENV !== "production") globalThis.prisma = client;

export default client;
‘’’