I'm trying to deploy my site after have added prisma, but keep getting this error and I don't know how to fix this.
PrismaClientKnownRequestError:
Invalid `prisma.product.findMany()` invocation:
Raw query failed. Code: `unknown`. Message: `Kind: Server selection timeout: No available servers. Topology: { Type: ReplicaSetNoPrimary, Set Name: atlas-3d8clu-shard-0, Servers: [ { Address: ac-fysecpf-shard-00-01.7qknsd4.mongodb.net:27017, Type: Unknown, Error: Kind: I/O error: received fatal alert: InternalError, labels: {} }, { Address: ac-fysecpf-shard-00-00.7qknsd4.mongodb.net:27017, Type: Unknown, Error: Kind: I/O error: received fatal alert: InternalError, labels: {} }, { Address: ac-fysecpf-shard-00-02.7qknsd4.mongodb.net:27017, Type: Unknown, Error: Kind: I/O error: received fatal alert: InternalError, labels: {} } ] }, labels: {}`
at _n.handleRequestError (/vercel/path0/node_modules/@prisma/client/runtime/library.js:121:7749)
at _n.handleAndLogRequestError (/vercel/path0/node_modules/@prisma/client/runtime/library.js:121:7057)
at _n.request (/vercel/path0/node_modules/@prisma/client/runtime/library.js:121:6741)
at async l (/vercel/path0/node_modules/@prisma/client/runtime/library.js:130:9355)
at async j (/vercel/path0/.next/server/pages/produto/[id].js:1:2826)
at async buildStaticPaths (/vercel/path0/node_modules/next/dist/build/utils.js:786:33)
at async /vercel/path0/node_modules/next/dist/build/utils.js:1215:110
at async Span.traceAsyncFn (/vercel/path0/node_modules/next/dist/trace/trace.js:151:20) {
code: 'P2010',
clientVersion: '5.18.0',
meta: {
modelName: 'Product',
I checked everything, I searched on Google but nothing looks like that
The problem was on getStaticPaths function, instead of passing the id, I passed the object
export async function getStaticPaths() {
const productsIds = await prisma.product.findMany();
return {
paths: productsIds.map((id) => ({
params: { id: id.toString() },
})),
fallback: true, // false or "blocking"
};
The correction:
export async function getStaticPaths() {
const productsIds = await prisma.product.findMany({
select: {id: true},
});
return {
paths: productsIds.map((product) => ({
params: { id: product.id.toString() },
})),
fallback: 'blocking', // false or "blocking"
};
}