Deployment to Vercel Error: PrismaClientInitializationError
Asked Answered
L

5

8

I'm trying to deploy to Vercel but my deployment crashed due to the following problem:

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

I created a global PrismaClient as recommended in the docs in my app/lib dir:

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;

So I'm not sure what the issue is

Lois answered 27/6, 2023 at 21:28 Comment(0)
M
9

the solution to your problem is just in the link inside the error. Reading carefully error messages can save you a lot of time :)

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

Madura answered 27/6, 2023 at 22:19 Comment(2)
I still cant see it in the error can you show where it is In the errorPhonotypy
@LahiruLankaRathnayaka it's in the second line.Madura
G
7

You can go to your project settings and override the build command like this :

Vercel override build command for prisma

Governance answered 16/1 at 16:18 Comment(0)
P
1

open your package.json file

{
  "name": "authjs_v5",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  }
}

In the scripts section, add these lines:

  • "postinstall": "prisma generate",
  • "build": "prisma generate && next build",
Purdy answered 2/3 at 11:2 Comment(0)
L
1

My solution:

old package.json

"scripts": {
    "dev": "next dev",
    "build": "npx prisma generate && next build",
    "start": "next start",
    "lint": "next lint",
    "postinstall": "npx prisma generate"
  },

new package.json

"scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint",
  },
Liddie answered 20/3 at 8:2 Comment(0)
C
1
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"start": "node build/index.js",
"build": "npx prisma generate && npm install && tsc",
"prestart": "npm run build",
"dev": "tsc-watch --onSuccess \"npm start\""
},
Catlin answered 6/5 at 9:58 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.