Home / Articles / Upgrade Prisma to v7 in a Next.js app with driver adapters

This article is published in English.

Upgrade Prisma to v7 in a Next.js app with driver adapters

ESM, schema/generator updates, dotenv, config modules, and client instantiation via driver adapters.

636 words

Prisma v7 brings ES module defaults, new client instantiation, and driver adapters. Upgrading a Next.js app is a sequenced checklist rather than a single version bump.

Minimum requirements

Node.js 20.19+ (22.x recommended), TypeScript 5.4+, and a Next.js version compatible with your ESM settings.

Upgrade steps

1. Update dependencies

Bump prisma and @prisma/client to v7 together.

2. Enable ES module support

Set "type": "module" where required and fix import extensions/paths that CJS previously forgave.

3. Update Prisma schema

Apply generator/provider changes documented for v7; regenerate after edits.

4. Install dotenv if needed

Load env explicitly when the new entrypoints no longer auto-load .env the old way.

5. Create Prisma config file

Centralize datasource URLs and adapter setup in the supported config module.

6. Update client instantiation with driver adapters

npm install @prisma/client@7
npm install -D prisma@7
{
  "type": "module",
  "scripts": {...}
}
generator client {
  provider = "prisma-client-js"
  engineType = "binary"
  output = "./generated"
}
generator client {
  provider = "prisma-client"
}
npm install dotenv
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config'

export default defineConfig({
  schema: 'prisma/schema.prisma',
  migrations: {
    path: 'prisma/migrations',
    seed: 'tsx prisma/seed.ts',
  },
  datasource: {
    url: env('DATABASE_URL'),
  },
})
npm install @prisma/adapter-pg
// db/index.ts

import { PrismaClient } from '@prisma/client';

const globalForPrisma = global as unknown as {
  prisma: PrismaClient;
};
const prisma =
  globalForPrisma.prisma ||
  new PrismaClient();

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;

export default prisma;
// db/index.ts

import { PrismaClient } from "@prisma/client";
import { Pool } from "pg";
import { PrismaPg } from "@prisma/adapter-pg";

// postgreSQL adapter for prisma 7
const pool = new Pool({
  connectionString: process.env.DATABASE_URL!,
});

const adapter = new PrismaPg(pool);

const globalForPrisma = global as unknown as {
  prisma: PrismaClient;
};

const prisma =
  globalForPrisma.prisma ||
  new PrismaClient({
    adapter,
  });

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;

export default prisma;
// app/api/users/route.ts

import { prisma } from '@/lib/prisma';
import { NextResponse } from 'next/server';

export async function GET() {
  try {
    const users = await prisma.user.findMany();
    return NextResponse.json(users);
  } catch (error) {
    return NextResponse.json(
      { error: 'Failed to fetch users' },
      { status: 500 }
    );
  }
}
npx prisma generate
npm run dev
rm -rf node_modules package-lock.json
npm install
npx prisma generate

Wire the adapter for your database driver instead of relying on deprecated constructors.

8. Regenerate Prisma Client

prisma generate after schema/config settles.

9. Testing your migration

Run migrations against a disposable database, hit critical Next.js route handlers, and confirm edge/server runtime imports resolve.

Common issues

  • Mixed CJS/ESM imports in lib/prisma.ts
  • Wrong Node engine on CI
  • Forgetting to regenerate client after adapter changes
  • Edge runtime importing Node-only drivers

Land the adapter and ESM changes in one PR with a smoke test on create/read/update paths.

Keep a single Prisma client singleton for server runtimes to avoid exhausting connection pools in Next.js dev HMR.

Document which routes run on Edge versus Node; adapters differ and silent fallbacks cause flaky prod-only failures.

Keep a single Prisma client singleton for server runtimes to avoid exhausting connection pools in Next.js dev HMR.

After regenerating the client, delete stale .next build caches so Next.js does not import an old Prisma client shape from a previous compile.

Verify connection pooling settings when switching adapters—serverless and long-running Node servers want different pool sizes.