Skip to content

Need to also clear global.prisma and globalThis.prisma #20

@flybayer

Description

@flybayer

According to https://github.com/prisma/prisma-client-js/issues/228#issuecomment-618433162, we must use the below code in next.js environments to prevent the too many connections error.

import { PrismaClient } from "@prisma/client"
export * from "@prisma/client"

let prisma: PrismaClient

if (process.env.NODE_ENV === "production") {
    prisma = new PrismaClient()
} else {
    // Ensure the prisma instance is re-used during hot-reloading
    // Otherwise, a new client will be created on every reload
    globalThis["prisma"] = globalThis["prisma"] || new PrismaClient()
    prisma = globalThis["prisma"]
}

export default prisma

Right now with that code this plugin is worthless, because prisma doesn't get reinstantiated.

Proposal

On prisma schema change, in addition to clearing the require cache, also delete global.prisma and globalThis.prisma

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions