Repository navigation
Description
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
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
Antovex commentedon Jan 13, 2026
I think the Issue is
The .next build output contains hardcoded references to a specific Prisma client hash, but you're:
Solutions
Option 1: Upload node_modules
Option 2: Don't regenerate Prisma on deploy
Remove
npx prisma generatefrom 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:
Option 4: Use standalone Next.js output
In next.config.ts:
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.)
yasasalwis commentedon Jan 13, 2026
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?
Antovex commentedon Jan 13, 2026
I think this is most likely a NextJS 16 & Turbopack Bug as it shouldn't be bundled and should be treated as external.
DylanA0110 commentedon Jan 21, 2026
i have the same problem
DylanA0110 commentedon Jan 21, 2026
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.
🐛 Fix: Use transpilePackages for Prisma to resolve Turbopack hash mis…