Skip to content

Cannot find module '@prisma/client-xxxxxxxxxxxxxxxx'. #29025

Open

Description

@yasasalwis

Bug description

When CICD deploy the NextJs app to production the server fails due to Prisma Error, Error: Cannot find module '@prisma/client-xxxxxxxxxxxxxxxx'. The CICD, Dev and Prod envs use same configurations.

What have i done so far:
Cleared Cache. (Both CICD and Prod).
Added serverExternalPackages: ['@prisma/client', 'pg'] to the config.

Severity

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

Reproduction

Build:

build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

  - name: Setup Node.js
    uses: actions/setup-node@v4
    with:
      node-version: '24'
      cache: 'npm'

  - name: Install dependencies
    run: npm ci

  - name: Generate Prisma Client
    run: npx prisma generate
    env:

  - name: Build
    run: npm run build

  - name: Upload Build Artifact
    uses: actions/upload-artifact@v4
    with:
      name: nextjs-build-dev
      path: |
        .next
        public
        package.json
        package-lock.json
        next.config.ts
        next.config.js
        prisma
      include-hidden-files: true

Deploy:
needs: build-and-test
runs-on: ubuntu-latest
steps:
- name: Download Build Artifact
uses: actions/download-artifact@v4
with:
name: nextjs-build-dev
path: ./

  - name: Deploy with rsync
    run: |
      # --delete ensures we remove any stray files on the server
      rsync -avz Config-Removed

  - name: Restart Application
    uses: appleboy/ssh-action@master
    with:
      CONFIG REMOVED
      script: |
        export NVM_DIR="$HOME/.nvm"
        [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
        nvm use 24
        
        cd /path-to/app
        
        rm -rf node_modules
        npm ci --omit=dev
        
        # 2. Generate Prisma Client
        npx prisma generate
        
        # 3. Clear Cache
        rm -rf .next/cache
        
        pm2 flush
        pm2 reload app-name

Expected vs. Actual Behavior

Connect to the server correctly

Frequency

Consistently reproducible

Does this occur in development or production?

Only in production (e.g., query engine, generated client)

Is this a regression?

Yes worked on 6

Workaround

force the next build for webpack

Prisma Schema & Queries

generator client {
provider = "prisma-client-js"
}

datasource db {
provider = "postgresql"
}

enum SubscriptionTier {
TIER1
TIER2
TIER3
}

enum Role {
ROLE1
ROLE2
}

enum IdeaStatus {
PLANNED
FILMED
POSTED
}

model User {
id String @id @default(uuid())
email String @unique
subscriptionTier SubscriptionTier @default(FREE)
credits Int @default(5)
role Role @default(ROLE1)
region String?
createdAt DateTime @default(now())
updatedAt DateTime @updatedat
}

Prisma Config

// This file was generated by Prisma, and assumes you have installed the following:
// npm install --save-dev prisma dotenv
import "dotenv/config";
import {defineConfig, env} from "prisma/config";

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

Logs & Debug Info

Error: Failed to load external module @prisma/client-xxxxxxxxxxxxxxxx: Error: Cannot find module '@prisma/client-xxxxxxxxxxxxxxxx'
Require stack:

  • /home/user/apps/app-name/.next/server/chunks/[root-of-the-server]__42449efc._.js
  • /home/user/apps/app-name/.next/server/chunks/[turbopack]_runtime.js
  • /home/user/apps/app-name/.next/server/app/api/cron/process-batch/route.js
  • /home/user/apps/app-name/node_modules/next/dist/server/require.js
  • /home/user/apps/app-name/node_modules/next/dist/server/load-components.js
  • /home/user/apps/app-name/node_modules/next/dist/build/utils.js
  • /home/user/apps/app-name/node_modules/next/dist/build/swc/options.js
  • /home/user/apps/app-name/node_modules/next/dist/build/swc/index.js
  • /home/user/apps/app-name/node_modules/next/dist/build/next-config-ts/transpile-config.js
  • /home/user/apps/app-name/node_modules/next/dist/server/config.js
  • /home/user/apps/app-name/node_modules/next/dist/cli/next-test.js
  • /home/user/apps/app-name/node_modules/next/dist/bin/next
    at Context.externalRequire [as x] (.next/server/chunks/[turbopack]runtime.js:535:15)
    at module evaluation (.next/server/chunks/[root-of-the-server]__42449efc.
    .js:1:1144)
    at instantiateModule (.next/server/chunks/[turbopack]_runtime.js:740:9)
    at getOrInstantiateModuleFromParent (.next/server/chunks/[turbopack]_runtime.js:763:12)
    at Context.esmImport [as i] (.next/server/chunks/[turbopack]runtime.js:228:20)
    at (.next/server/chunks/[root-of-the-server]__42449efc.
    .js:1:2884)
    at Context.asyncModule [as a] (.next/server/chunks/[turbopack]runtime.js:455:5)
    at module evaluation (.next/server/chunks/[root-of-the-server]__42449efc.
    .js:1:2857)
    at instantiateModule (.next/server/chunks/[turbopack]_runtime.js:740:9)
    at getOrInstantiateModuleFromParent (.next/server/chunks/[turbopack]_runtime.js:763:12)
    ⨯ unhandledRejection: Error: Failed to load external module @prisma/client-xxxxxxxxxxxxxxxx: Error: Cannot find module '@prisma/client-xxxxxxxxxxxxxxxx'
    Require stack:
  • /home/user/apps/app-name/.next/server/chunks/[root-of-the-server]__42449efc._.js
  • /home/user/apps/app-name/.next/server/chunks/[turbopack]_runtime.js
  • /home/user/apps/app-name/.next/server/app/api/cron/process-batch/route.js
  • /home/user/apps/app-name/node_modules/next/dist/server/require.js
  • /home/user/apps/app-name/node_modules/next/dist/server/load-components.js
  • /home/user/apps/app-name/node_modules/next/dist/build/utils.js
  • /home/user/apps/app-name/node_modules/next/dist/build/swc/options.js
  • /home/user/apps/app-name/node_modules/next/dist/build/swc/index.js
  • /home/user/apps/app-name/node_modules/next/dist/build/next-config-ts/transpile-config.js
  • /home/user/apps/app-name/node_modules/next/dist/server/config.js
  • /home/user/apps/app-name/node_modules/next/dist/cli/next-test.js
  • /home/user/apps/app-name/node_modules/next/dist/bin/next
    at Context.externalRequire [as x] (.next/server/chunks/[turbopack]runtime.js:535:15)
    at module evaluation (.next/server/chunks/[root-of-the-server]__42449efc.
    .js:1:1144)
    at instantiateModule (.next/server/chunks/[turbopack]_runtime.js:740:9)
    at getOrInstantiateModuleFromParent (.next/server/chunks/[turbopack]_runtime.js:763:12)
    at Context.esmImport [as i] (.next/server/chunks/[turbopack]runtime.js:228:20)
    at (.next/server/chunks/[root-of-the-server]__42449efc.
    .js:1:2884)
    at Context.asyncModule [as a] (.next/server/chunks/[turbopack]runtime.js:455:5)
    at module evaluation (.next/server/chunks/[root-of-the-server]__42449efc.
    .js:1:2857)
    at instantiateModule (.next/server/chunks/[turbopack]_runtime.js:740:9)
    at getOrInstantiateModuleFromParent (.next/server/chunks/[turbopack]_runtime.js:763:12)

Environment & Setup

OS: Linux (Ubuntu LTS)
TurboPack
NVM:0.40.3
Node: v24.12.0
Next : 16.1.1
CICD Pipeline: GitHub Actions.

Prisma Version

7.2.0

Activity

  1. added
    kind/bug
    on Jan 13, 2026
  2. Antovex commented on Jan 13, 2026

    @Antovex

    I think the Issue is
    The .next build output contains hardcoded references to a specific Prisma client hash, but you're:

    • Building with one Prisma client instance in the build and test stage (hash A)
    • Deploying the build artifacts
    • Regenerating a potentially different Prisma client (hash B)
    • Next.js tries to load the old hash (A) but only hash B exists

    Solutions

    Option 1: Upload node_modules

    - name: Upload Build Artifact
      uses: actions/upload-artifact@v4
      with:
        name: nextjs-build-dev
        path: |
          .next
          node_modules/@prisma  # Include the Prisma client that was built with
          public
          # ... rest

    Option 2: Don't regenerate Prisma on deploy
    Remove npx prisma generate from the deployment script since the build artifact already has it.

    Option 3: Build on the production server
    Instead of building in CI and deploying artifacts, deploy the source code and build directly on production:

    rsync -avz --exclude . next --exclude node_modules ... 
    ssh ...  "npm ci && npx prisma generate && npm run build && pm2 reload"

    Option 4: Use standalone Next.js output
    In next.config.ts:

    export default {
      output: 'standalone',
      // ... 
    }

    This creates a self-contained build that includes all dependencies.

    (Note: I am still a fresher and I have taken help of AI to get to this.)

  3. yasasalwis commented on Jan 13, 2026

    @yasasalwis
    Author

    in the rsync node_modules are excluded which prisma client generated. That's why I generate the client at the prod. As a practice I don't build the app on the prod server. I also set the prisma as external package using:

    serverExternalPackages: ['@prisma/client', '@prisma/adapter-pg', 'pg']

    Thanks for the input!
    Maybe this is related to Turbopack?

  4. Antovex commented on Jan 13, 2026

    @Antovex

    I think this is most likely a NextJS 16 & Turbopack Bug as it shouldn't be bundled and should be treated as external.

  5. DylanA0110 commented on Jan 21, 2026

    @DylanA0110

    i have the same problem

  6. DylanA0110 commented on Jan 21, 2026

    @DylanA0110

    With AI and documentation, I came up with a solution. I changed the next.config and put this:
    // Bundle Prisma + pg under Turbopack to avoid external hashing issues.
    transpilePackages: ['@prisma/client', '@prisma/adapter-pg', 'pg'],

    Then I booted the next folder, ran npm run dev again with turbopack, and it was resolved, including prisma.ts. I put import 'server-only'; so that it wouldn't try to go to the client. It was my only solution.

  7. added
    bug/1-unconfirmed
    on Feb 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug/1-unconfirmedkind/bug

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions