next.js 部署到Vercel错误:PrismaClientInitializationError

ut6juiuv  于 2023-06-29  发布在  Mac
关注(0)|答案(1)|浏览(268)

我正在尝试部署到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

我按照我的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;

所以我不知道问题出在哪

6psbrbz9

6psbrbz91#

你的问题的解决方案就在错误里面的链接里。仔细阅读错误信息可以保存很多时间:)
https://pris.ly/d/vercel-build

相关问题