PrismaP
Prisma3mo ago
11 replies
oscarthroedsson

Can´t generate prisma global next.js 15.5.6 (Next.js-supabase-prisma)

Hi everyone,

I am trying to start up a new app with the following stack:

Next.js: 15.5.6
Database: Supabase
ORM: Prisma Client 6.18.0

#Explanation of setup
I have my own project (not following the full “create-next-app” guide). I have been following the Prisma Next.js guide:
https://www.prisma.io/docs/guides/nextjs

In this guide it doesn´t say to run
npx prisma migrate
npx prisma generate


#Files
Prisma.config
import "dotenv/config";
import { defineConfig } from "prisma/config";
import { getSupabaseURL } from "./lib/env";

export default defineConfig({
  schema: "prisma/schema.prisma",
  migrations: {
    path: "prisma/migrations",
  },
  engine: "classic",
  datasource: {
    url: getSupabaseURL(),
  },
});

import process from "process";

export const getSupabaseURL = (): string => {
  const NODE_ENV = process.env.NODE_ENV ?? "development";
  console.log(":palm_tree: env Environment:", NODE_ENV);

  const DATABASE_PRODUCTION_URL = process.env.DATABASE_PRODUCTION_URL;
  const DATABASE_LOCAL_URL = process.env.DATABASE_LOCAL_URL;

  if (!DATABASE_PRODUCTION_URL || !DATABASE_LOCAL_URL) throw new Error("[env.ts] Supabase URL is undefined");

  return NODE_ENV === "production" ? DATABASE_PRODUCTION_URL : DATABASE_LOCAL_URL;
};

Schema.prisma
generator client {
  provider = "prisma-client"
  output   = "../generated/prisma"
}

datasource db {
  provider  = "postgresql"
  url       = env("DATABASE_LOCAL_URL")
  directUrl = env("DIRECT_URL")
}


What I want

I wan´t to be able to import prismaclient as instructed and be able to have a global instance of it. But when I do this:
import { PrismaClient } from "@/generated/prisma";

I get the following error:
Cannot find module '@/generated/prisma' or its corresponding type declarations.ts(2307)

I have once cleared my DB, uninstalled prisma, deleted everything and set up everything again... But get the same error.

I would like some guidance or more question to help me figure things out..

Thanks in advanded
Learn how to use Prisma ORM in a Next.js app and deploy it to Vercel
How to use Prisma ORM and Prisma Postgres with Next.js 15 and Verce...
Solution

Solution

In the prisma.schema file, changed provider
from: "prisma-client"
to: "prisma-client-js"

This is my Prisma files:

schema.prisma
generator client {
  provider = "prisma-client-js" // ← 
  // output   = "../generated/prisma" // no output → the output will be in node_modules
}

datasource db {
  provider = "postgresql"
  url      = env("DATABASE_PRODUCTION_URL")
}


prisma.config.ts
import "dotenv/config";
import { defineConfig, env } from "prisma/config";

export default defineConfig({
  schema: "prisma/schema.prisma",
  migrations: {
    path: "prisma/migrations",
  },
  engine: "classic",
  datasource: {
    url: env("DIRECT_URL"),
  },
});


/lib/prisma.ts
// lib/prisma.ts
/*
This will take PrismaClient from prisma folder in node_modules and the code provide a prisma client global and will only initiate once at start
*/
import { PrismaClient } from "@prisma/client";

// func to initiate prisma client
const prismaClientSingelton = () => {
  return new PrismaClient();
};

// Type 
declare const globalThis: {
  prismaGlobal: ReturnType<typeof prismaClientSingelton>;
} & typeof global;

// Use existing or initiate 
const prisma = globalThis.prismaGlobal ?? prismaClientSingelton();

// exports it so we can use it in other files
export default prisma;

// Add prisma to hhe global instance if we aren´t in production
/*
⚠️ I don´t know yet how I will solve this in production or if it needs solving (prob will)
*/
if (process.env.NODE_ENV !== "production") globalThis.prismaGlobal = prisma;
Was this page helpful?