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
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;
};
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")
}
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";
import { PrismaClient } from "@/generated/prisma";
I get the following error:
Cannot find module '@/generated/prisma' or its corresponding type declarations.ts(2307)
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
How to use Prisma ORM and Prisma Postgres with Next.js 15 and Verce...
Learn how to use Prisma ORM in a Next.js app and deploy it to Vercel
Solution:
Solution In the prisma.schema file, changed provider from: "prisma-client" to: "prisma-client-js" ...
Jump to solution
7 Replies
Prisma AI Help
You've gone full bot mode! Let me fetch that AI answer for you ASAP. Your error:
Cannot find module '@/generated/prisma' or its corresponding type declarations.ts(2307)
Cannot find module '@/generated/prisma' or its corresponding type declarations.ts(2307)
means the Prisma Client was not generated at the expected output path. This is a common issue if you haven't run npx prisma generate after setting up your schema and generator output path. Key steps to resolve: 1. Run prisma generate:
After editing your schema.prisma, you must run:
npx prisma generate

npx prisma generate

This will generate the client in generated/prisma as specified in your generator block. This step is required every time you change your schema or generator config. The official docs and community threads confirm this is necessary, even if not always explicitly stated in every guide [Generating Prisma Client]. 2. Check your import path:
Your import should match the output path. If your output is ../generated/prisma relative to prisma/schema.prisma, then from your app code (e.g., src/lib/prisma.ts), the import should be:
import { PrismaClient } from "@/generated/prisma";

import { PrismaClient } from "@/generated/prisma";

Make sure your tsconfig.json has the correct path alias for @/generated/prisma. 3. Add to .gitignore:
Exclude the generated client from version control:
/generated/prisma

/generated/prisma

[Getting started] 4. Automate generation:
Add a script to your package.json to ensure the client is generated after install:
"scripts": {
"postinstall": "prisma generate"
}

"scripts": {
"postinstall": "prisma generate"
}

[Module '"@prisma/client"' has no exported member 'PrismaClient'] Summary:
You must run npx prisma generate after setting up your schema and generator. This will create the client at the specified output path, resolving the import error. If you still have issu es, double-check your paths and that the generated folder exists. If you follow these steps and still see the error, please share your project structure and the exact location of your import statement. 🤔 Alright, thanks for letting us know that there's still some help needed. A team member will reply to you shortly. In the meantime, please let us know any additional info, questions, or which parts of the answer may need clarification.
oscarthroedsson
oscarthroedssonOP5w ago
Project structure: root/prisma/migrations root/prisma/prisma.schema root/lib/prisma.ts root/generated/prisma Files inside /primsa (IMG) I have tried the following imports in prisma.ts
import { PrismaClient } from "@/generated/prisma"; Error → *signUpWithProvider Cannot find module '@/generated/prisma' or its corresponding type declarations.ts(2307)
import { PrismaClient } from "@prisma/client";
No description
oscarthroedsson
oscarthroedssonOP5w ago
I
Aman
Aman4w ago
try this schema
generator client {
provider = "prisma-client"
output = "./generated"
engineType = "client"
}
generator client {
provider = "prisma-client"
output = "./generated"
engineType = "client"
}
run prisma generate then import the prisma client like this import { PrismaClient } from "../prisma/generated/client" @oscarthroedsson
Aman
Aman4w ago
you need to add a path alias for prisma if you dont want to use relative import Add a path in tsconfig
No description
oscarthroedsson
oscarthroedssonOP4w ago
Thanx for tips. The only thing that worked was using a provider as: ”prisma-client-js”
Solution
oscarthroedsson
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")
}
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"),
},
});
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;
// 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;

Did you find this page helpful?