部署到 Vercel 错误:PrismaClientInitializationError

Mat*_*hew 7 next.js vercel prisma

我正在尝试部署到 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.
Learn how: https://pris.ly/d/vercel-build
    at eu (/vercel/path0/node_modules/@prisma/client/runtime/library.js:164:69)
    at new t (/vercel/path0/node_modules/@prisma/client/runtime/library.js:177:3203)
    at 40754 (/vercel/path0/.next/server/chunks/578.js:138:37)
    at __webpack_require__ (/vercel/path0/.next/server/webpack-runtime.js:25:43)
    at 76578 (/vercel/path0/.next/server/chunks/578.js:23:16)
    at __webpack_require__ (/vercel/path0/.next/server/webpack-runtime.js:25:43)
    at 32631 (/vercel/path0/.next/server/app/(site)/home/page.js:4370:22)
    at Function.__webpack_require__ (/vercel/path0/.next/server/webpack-runtime.js:25:43)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async collectGenerateParams (/vercel/path0/node_modules/next/dist/build/utils.js:822:17) {
  clientVersion: '4.15.0',
  errorCode: undefined
}
> Build error occurred
Error: Failed to collect page data for /home
    at /vercel/path0/node_modules/next/dist/build/utils.js:1155:15
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
  type: 'Error'
}
Error: Command "npm run build" exited with 1
BUILD_UTILS_SPAWN_1: Command "npm run build" exited with 1
Run Code Online (Sandbox Code Playgroud)

我按照 app/lib 目录中的文档中的建议创建了一个全局 PrismaClient:

import { PrismaClient } from "@prisma/client";

declare global {
  var prisma: PrismaClient | undefined;
}

const client = globalThis.prisma || new PrismaClient();
if (process.env.NODE_ENV !== "production") globalThis.prisma = client;

export default client;
Run Code Online (Sandbox Code Playgroud)

所以我不确定问题是什么

小智 7

您的问题的解决方案就在错误内的链接中。仔细阅读错误消息可以节省您很多时间:)

https://pris.ly/d/vercel-build