Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

NextJS + Prisma 部署到 Vercel 遇到的坑 #42

Open
yankewei opened this issue Jul 13, 2024 · 0 comments
Open

NextJS + Prisma 部署到 Vercel 遇到的坑 #42

yankewei opened this issue Jul 13, 2024 · 0 comments

Comments

@yankewei
Copy link
Owner

yankewei commented Jul 13, 2024

部署之前需要重新使用 Prisma 进行 generate

如果你进行了数据库结构变更,例如给一个数据表增加了唯一索引,在本地 Prisma 已经重新生成了 PrismaClient,所以本地 build 没有任何报错,但是当你的项目构建在 Vercel 上,Prisma 不会重新 generate,而是利用已有的 dependencies,导致出现一些 type error,比如说你是用了 findUnique,会告诉你 where 条件的字段不匹配。在 Vercel 构建的时候,也会有日志提示,如下:

PrismaClientInitializationError: Prisma has detected that this project was built on Vercel, which caches dependencies. This leads to an outdated Prisma Client because Prisma's auto-generation isn't triggered. To fix this, make sure to run the prisma generate command during the build process.
你可以在package.json添加一些预构建脚本,

{
  "scripts": {
    "dev": "next dev",
    "prebuild": "prisma migrate deploy && prisma generate",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant