Thanks to visit codestin.com
Credit goes to Github.com

Skip to content

Migrating to Prisma v7 fails when connecting to a local database #28950

@craigmcc

Description

@craigmcc

Bug description

I have a NextJS application that runs just fine with talking to a Postgres database with 6.12.0. I'm trying to follow the migration guide so I can use 7.2.0. All the configuration changes were completed, but when I try to run the application, it generates the following runtime error the first time a connection to the database is attempted:

⨯ ../../node_modules/.pnpm/[email protected]/node_modules/pg-connection-string/index.js:81:1
Module not found: Can't resolve 'fs'
79 |
80 | // Only try to load fs if we expect to read from the disk

81 | const fs = config.sslcert || config.sslkey || config.sslrootcert ? require('fs') : null
| ^
82 |
83 | if (config.sslcert) {
84 | config.ssl.cert = fs.readFileSync(config.sslcert).toString()

https://nextjs.org/docs/messages/module-not-found

Import trace for requested module:
../../node_modules/.pnpm/[email protected]/node_modules/pg/lib/connection-parameters.js
../../node_modules/.pnpm/[email protected]/node_modules/pg/lib/client.js
../../node_modules/.pnpm/[email protected]/node_modules/pg/lib/index.js
../../node_modules/.pnpm/[email protected]/node_modules/pg/esm/index.mjs
../../node_modules/.pnpm/@prisma[email protected]/node_modules/@prisma/adapter-pg/dist/index.mjs
../../packages/db-shopshop/dist/client.js
../../packages/db-shopshop/dist/index.js
./src/components/lists/ListsTable.tsx
⨯ ../../node_modules/.pnpm/[email protected]/node_modules/pg-connection-string/index.js:81:1

The interesting aspect here is that I'm trying to connect to a local Postgres database, so it should not be trying to load the "fs" module (no SSL involved here). My database URL looks like this (with the credentials obfuscated):

DATABASE_URL="postgresql://{USERNAME}:{PASSWORD}@localhost:5432/shopshop?schema=public"

Severity

⚠️ Major: Breaks core functionality (e.g., migrations fail)

Reproduction

I could point you at my application on GitHub, but it would take hours for you a long time to set up the needed environment and database.

The issue is that the app cannot build because of the error message described above.

Expected vs. Actual Behavior

Expected: As it does with Prisma 6, the database connects and returns the requested data.

Actual: Trying to build the app fails with the error quoted above. Same thing happens in dev mode as soon as I access a page that needs the database.

Frequency

Consistently reproducible

Does this occur in development or production?

Only in development (e.g., CLI tools, migrations, Prisma Studio)

Is this a regression?

Not a regression. The same database and application work fine with 6.12.0.

Workaround

No known workaround.

Prisma Schema & Queries

// Top of the revised Schema
generator client {
  provider = "prisma-client"
  output   = "../generated/prisma"
}

datasource db {
  provider = "postgresql"
}

/// Model for an Individual shopping list
model List {
  /// Primary key for this List
  id       String  @id @default(uuid())
  /// Optional avatar image URL for this List
  imageUrl String? @map("image_url") @db.Text
  /// List's name
  name     String  @db.Text
  /// Should this List be private (not shareable with other users)?
  private  Boolean @default(false)

  /// Created at timestamp
  createdAt DateTime @default(now()) @map("created_at")
  /// Updated at timestamp
  updatedAt DateTime @updatedAt @map("updated_at")

  /// Categories belonging to this List
  categories Category[]

  /// Items belonging to this List
  items Item[]

  /// Members of this List
  members Member[]

  // /// ID of the Profile that created this List
  // profileId String
  // /// Profile that created this List
  // profile   Profile  @relation(fields: [profileId], references: [id], onDelete: Cascade)
  //
  // @@index([profileId])
  @@map("lists")
}

/// Related Members model
/// Membership of a particular Profile to a particular List
model Member {
  /// Primary key for this Member
  id   String     @id @default(uuid())
  /// Role of this Member on this List
  role MemberRole @default(GUEST)

  /// Created at timestamp
  createdAt DateTime @default(now()) @map("created_at")
  /// Updated at timestamp
  updatedAt DateTime @updatedAt @map("updated_at")

  /// ID of the List that is the subject of this Membership
  listId    String  @map("list_id")
  /// List that is the subject of this Membership
  list      List    @relation(fields: [listId], references: [id], onDelete: Cascade)
  /// ID of the Profile that is the subject of this Membership
  profileId String  @map("profile_id")
  /// Profile that is the subject of this Membership
  profile   Profile @relation(fields: [profileId], references: [id], onDelete: Cascade)

  @@index([listId])
  @@index([profileId])
  @@map("members")
}

/// Role of a Member in a List
enum MemberRole {
  ADMIN
  GUEST
}
// The first query encountered:
  const memberships = await dbShopShop.member.findMany({
    include: {
      list: true,
    },
    orderBy: [
      { list: { name: "asc" } },
    ],
    where: {
      profileId: profile.id,
    },
  });

Because this is an attempted migration from Prisma 6 to Prisma 7, here's the related configuration files (based on the migration guide):

// client.ts
import { PrismaClient } from "../generated/prisma/client";
import { PrismaPg } from '@prisma/adapter-pg';

const adapter = new PrismaPg({
  connectionString: process.env.DATABASE_URL,
});

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

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

if (process.env.NODE_ENV !== "production") globalForPrisma.prisma = prisma;
// index.ts
export { prisma as dbShopShop } from './client' // exports instance of prisma
export * from "../generated/prisma/client" // exports generated types from prisma

Prisma Config

// Add your `prisma.config.ts`
import 'dotenv/config'
import { defineConfig, env } from 'prisma/config';

export default defineConfig({
  schema: 'prisma/schema.prisma',
  migrations: {
    path: 'prisma/migrations',
  },
  datasource: {
    url: env('DATABASE_URL'),
  },
});

Logs & Debug Info

// Debug logs here

I cannot actually run the query, because the application fails to build.

Environment & Setup

  • OS: MacOS 15.6.1
  • Database: PostgreSQL
  • Node.js version: 24.1.0
  • NextJS version: 15.5.7

Prisma Version

// Prisma version output
prisma               : 7.2.0
@prisma/client       : Not found
Operating System     : darwin
Architecture         : arm64
Node.js              : v24.1.0
TypeScript           : unknown
Query Compiler       : enabled
PSL                  : @prisma/prisma-schema-wasm 7.2.0-4.0c8ef2ce45c83248ab3df073180d5eda9e8be7a3
Schema Engine        : schema-engine-cli 0c8ef2ce45c83248ab3df073180d5eda9e8be7a3 (at ../../../../Library/Caches/pnpm/dlx/89a11a42a8776a5b2b0bd48e9d1987eaba044a26dc177d5effb8c49bdb39244d/19b43f272c1-75b7/node_modules/.pnpm/@[email protected]/node_modules/@prisma/engines/schema-engine-darwin-arm64)
Default Engines Hash : 0c8ef2ce45c83248ab3df073180d5eda9e8be7a3
Studio               : 0.9.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedBug should have enough information for reproduction, but confirmation has not happened yet.kind/bugA reported bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions