I am building a nextjs project on vercel with typescript and prisma. Versions: "next": "13.0.3" "typescript": "4.9.3" "prisma": "^4.6.1"
build is passing locally, but fails on vercel:
Type error: Property 'companies' does not exist on type 'PrismaClient<PrismaClientOptions, never, RejectOnNotFound \| RejectPerOperation \| undefined>'.
--
01:05:17.287 |
01:05:17.287 | 71 \| },
01:05:17.288 | 72 \| companies: async () => {
01:05:17.288 | > 73 \| const companies = await prisma.companies.findMany();
01:05:17.289 | \| ^
01:05:17.289 | 74 \| return companies;
01:05:17.289 | 75 \| },
01:05:17.289 | 76 \| },
whereas typescript detects 'companies' as property of prisma tried to regenerate Prisma Client, deleting the model and consequently using: prisma format, prisma generate, prisma db push. I am using mongodb
./prisma/schema.prisma
model companies {
id String @id @default(auto()) @map("_id") @db.ObjectId
v Int? @map("__v")
name String
}
production builds were passing before adding this new model
You would need to make sure that npx prisma generate
is a part of your build process.
In your package.json you can define the generate command in the build process like this:
{
"name": "deployment-example-prisma-vercel",
"dependencies": {
"@prisma/client": "4.7.1",
"next": "13.0.6",
"react": "18.2.0",
"react-dom": "18.2.0"
},
"scripts": {
"dev": "next dev",
"build": "next build",
"start": "next start",
"vercel-build": "prisma generate && prisma migrate deploy && next build",
"prisma:generate": "prisma generate"
},
"devDependencies": {
"prisma": "4.7.1"
}
}
Here, invoking the vercel-build command would trigger the generate command to update the PrismaClient with newly added model. You can remove the migrate deploy command if you are not using Prisma Migrate.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With