extension-read-replicas
extension-read-replicas copied to clipboard
Next build fail when the project is using replicas
Relevant log
91 packages installed [7.51s]
Detected Next.js version: 15.1.4
Running "bun run vercel-build"
$ prisma generate && prisma migrate deploy && next build
Prisma schema loaded from prisma/schema.prisma
✔ Generated Prisma Client (v6.2.1) to ./node_modules/@prisma/client in 160ms
Start by importing your Prisma Client (See: https://pris.ly/d/importing-client)
Tip: Interested in query caching in just a few lines of code? Try Accelerate today! https://pris.ly/tip-3-accelerate
Prisma schema loaded from prisma/schema.prisma
Datasource "db": PostgreSQL database "asdasd", schema "asdasd" at "******.us-east-2.aws.neon.tech"
20 migrations found in prisma/migrations
No pending migrations to apply.
▲ Next.js 15.1.4
Creating an optimized production build ...
✓ Compiled successfully
Linting and checking validity of types ...
...
Error occurred prerendering page "/x/sitemap/id.xml". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of undefined (reading 'findFirst')
at Array.$allOperations (/vercel/path0/.next/server/app/x/sitemap/[__metadata_id__]/route.js:16:11261)
at /vercel/path0/node_modules/@prisma/client/runtime/library.js:31:9170
at i (/vercel/path0/node_modules/@prisma/client/runtime/library.js:121:1016)
at PrismaPromise.then (/vercel/path0/node_modules/@prisma/client/runtime/library.js:121:1091)
Export encountered an error on /x/sitemap/[__metadata_id__]/route: /x/sitemap/id.xml, exiting the build.
⨯ Static worker exited with code: 1 and signal: null
error: script "vercel-build" exited with code 1
Error: Command "bun run vercel-build" exited with 1
import "dotenv/config";
import { PrismaClient } from "@prisma/client";
// import { PrismaNeon } from "@prisma/adapter-neon";
// import { Pool, neonConfig } from "@neondatabase/serverless";
import { readReplicas } from "@prisma/extension-read-replicas";
// import ws from "ws";
// neonConfig.webSocketConstructor = ws;
// const connectionString = process.env.DATABASE_URL;
// const pool = new Pool({ connectionString });
// const adapter = new PrismaNeon(pool);
const replicas: string[] = [];
for (let i = 1; i <= 30; i++) {
const replica = process.env[`DATABASE_URL_REPLICA${i}`];
if (!replica) break;
replicas.push(replica);
}
declare global {
// eslint-disable-next-line no-var
var prisma: PrismaClient | undefined;
}
let db: PrismaClient; // Explicitly define the type of db
if (global.prisma) {
db = global.prisma;
} else if (replicas.length > 0) {
// console.log({ adapter });
db = new PrismaClient().$extends(
readReplicas({
url: replicas,
}),
) as unknown as PrismaClient;
global.prisma = db;
} else {
// console.log({ adapter });
db = new PrismaClient();
global.prisma = db;
}
export default db;
How did I fix this issue? commenting these lines
for (let i = 1; i <= 30; i++) {
const replica = process.env[`DATABASE_URL_REPLICA${i}`];
if (!replica) break;
replicas.push(replica);
}
next info
/bin/sh: line 1: pnpm: command not found
Operating System:
Platform: linux
Arch: x64
Version: #1 SMP Thu Jan 11 04:09:03 UTC 2024
Available memory (MB): 31931
Available CPU cores: 20
Binaries:
Node: 22.12.0
npm: 10.9.0
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 15.1.4 // Latest available version is detected (15.1.4).
eslint-config-next: 15.1.4
react: 19.0.0
react-dom: 19.0.0
typescript: 5.7.3
Next.js Config:
output: N/A
package.json
{
"name": "capy-school",
"version": "0.1.0",
"private": true,
"scripts": {
"dev": "NODE_OPTIONS='--inspect' next dev --turbopack",
"build": "next build",
"start": "next start",
"preview": "next start",
"lint": "next lint",
"format": "prettier --write .",
"format:check": "prettier --check .",
"test": "vitest",
"update:check": "ncu",
"update:fix": "ncu -u",
"slicemachine": "start-slicemachine",
"vercel-build": "prisma generate && prisma migrate deploy && next build",
"build-credentials": "bun scripts/build-credentials.ts",
"prisma": "prisma",
"db:push": "prisma db push",
"db:migrate": "prisma generate && prisma migrate deploy",
"db:migrate:new": "prisma migrate dev",
"indexnow": "bun scripts/index-now.ts"
},
"dependencies": {
"@aws-sdk/client-polly": "^3.726.0",
"@google-cloud/text-to-speech": "^5.7.0",
"@hookform/resolvers": "^3.10.0",
"@mdx-js/loader": "^3.1.0",
"@mdx-js/react": "^3.1.0",
"@neondatabase/serverless": "^0.10.4",
"@next/mdx": "^15.1.4",
"@next/third-parties": "^15.1.4",
"@prisma/adapter-neon": "^6.2.1",
"@prisma/client": "^6.2.1",
"@prisma/extension-read-replicas": "^0.4.0",
"@prismicio/client": "^7.14.0",
"@prismicio/next": "^1.7.1",
"@prismicio/react": "^2.9.1",
"@radix-ui/react-checkbox": "^1.1.3",
"@radix-ui/react-collapsible": "^1.1.2",
"@radix-ui/react-dialog": "^1.1.4",
"@radix-ui/react-dropdown-menu": "^2.1.4",
"@radix-ui/react-icons": "^1.3.2",
"@radix-ui/react-label": "^2.1.1",
"@radix-ui/react-navigation-menu": "^1.2.3",
"@radix-ui/react-popover": "^1.1.4",
"@radix-ui/react-radio-group": "^1.2.2",
"@radix-ui/react-scroll-area": "^1.2.2",
"@radix-ui/react-select": "^2.1.4",
"@radix-ui/react-separator": "^1.1.1",
"@radix-ui/react-slider": "^1.2.2",
"@radix-ui/react-slot": "^1.1.1",
"@radix-ui/react-switch": "^1.1.2",
"@radix-ui/react-tabs": "^1.1.2",
"@radix-ui/react-toast": "^1.2.4",
"@radix-ui/react-tooltip": "^1.1.6",
"@radix-ui/react-visually-hidden": "^1.1.1",
"@types/argon2": "^0.15.4",
"@types/bun": "^1.1.16",
"@types/lodash": "^4.17.14",
"@types/mdx": "^2.0.13",
"@types/ws": "^8.5.13",
"@vercel/blob": "^0.25.1",
"@vercel/flags": "^2.6.3",
"@vercel/functions": "^1.5.2",
"@vercel/toolbar": "^0.1.30",
"aws-sdk": "^2.1692.0",
"bufferutil": "^4.0.9",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"cmdk": "1.0.0",
"framer-motion": "^11.16.4",
"jose": "^5.9.6",
"lodash": "^4.17.21",
"lucide-react": "^0.456.0",
"next": "^15.1.4",
"next-intl": "^3.26.3",
"next-themes": "^0.3.0",
"next-translate": "^2.6.2",
"next-translate-plugin": "^2.6.2",
"react": "^19.0.0",
"react-confetti": "^6.2.2",
"react-dom": "^19.0.0",
"react-error-boundary": "^4.1.2",
"react-hook-form": "^7.54.2",
"react-use": "^17.6.0",
"recharts": "^2.15.0",
"remark": "^15.0.1",
"remark-html": "^16.0.1",
"server-only": "^0.0.1",
"stripe": "^17.5.0",
"tailwind-merge": "^2.6.0",
"tailwindcss-animate": "^1.0.7",
"undici": "^6.21.0",
"vaul": "^1.1.2",
"zod": "^3.24.1"
},
"devDependencies": {
"@next/bundle-analyzer": "^15.1.4",
"@slicemachine/adapter-next": "^0.3.61",
"@testing-library/react": "^16.1.0",
"@types/google-publisher-tag": "^1.20241202.0",
"@types/react": "npm:[email protected]",
"@types/react-dom": "npm:[email protected]",
"@types/uuid": "^10.0.0",
"@vitejs/plugin-react": "^4.3.4",
"eslint": "^8.57.1",
"eslint-config-next": "^15.1.4",
"eslint-config-prettier": "^9.1.0",
"eslint-config-turbo": "^2.3.3",
"eslint-plugin-prettier": "^5.2.1",
"eslint-plugin-tailwindcss": "^3.17.5",
"jsdom": "^25.0.1",
"npm-check-updates": "^17.1.13",
"postcss": "^8.4.49",
"prettier": "^3.4.2",
"prettier-plugin-prisma": "^5.0.0",
"prettier-plugin-tailwindcss": "^0.6.9",
"prisma": "^6.2.1",
"schema-dts": "^1.1.2",
"slice-machine-ui": "^2.11.1",
"tailwindcss": "^3.4.17",
"turbo": "^2.3.3",
"typescript": "^5.7.3",
"vercel": "^37.14.0",
"vitest": "^2.1.8"
},
"overrides": {
"@types/react": "^19.0.0-rc.1",
"@types/react-dom": "^19.0.0-rc.1"
}
}
Duplicate https://github.com/prisma/extension-read-replicas/issues/41