Issues with building Prisma & Next.js

Site name: di-report-card

The past couple of days, both me and some people from my team have been dealing with an issue regarding Prisma and Netlify. Out of nowhere, our builds stopped passing, complaining about “prisma generate” not having been run before but then it says it did in the logs which leaves me very ???

This is the most relevant part of the logs I believe:

pnpx prisma generate --schema prisma/schema.prisma && next build
5:26:37 PM: Progress: resolved 1, reused 0, downloaded 0, added 0
5:26:38 PM: Progress: resolved 3, reused 0, downloaded 3, added 0
5:26:39 PM: Packages: +6
5:26:39 PM: ++++++
5:26:39 PM: Progress: resolved 6, reused 0, downloaded 6, added 6, done
5:26:39 PM: .../node_modules/@prisma/engines postinstall$ node scripts/postinstall.js
5:26:39 PM: .../node_modules/@prisma/engines postinstall: Done
5:26:39 PM: .../prisma@5.18.0/node_modules/prisma preinstall$ node scripts/preinstall-entry.js
5:26:39 PM: .../prisma@5.18.0/node_modules/prisma preinstall: Done
5:26:40 PM: Prisma schema loaded from prisma/schema.prisma
5:26:41 PM: ✔ Generated Prisma Client (v5.9.1) to ./../../node_modules/.prisma/client in 263ms
5:26:41 PM: Start by importing your Prisma Client (See: http://pris.ly/d/importing-client)
5:26:41 PM: Tip: Curious about the SQL queries Prisma ORM generates? Optimize helps you enhance your visibility: https://pris.ly/tip-2-optimize
5:26:41 PM: warn Versions of prisma@5.18.0 and @prisma/client@5.9.1 don't match.
This might lead to unexpected behavior.
5:26:41 PM: Please make sure they have the same version.
5:26:42 PM: - warn No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
5:26:42 PM: - info Skipping validation of types
5:26:42 PM: - info Skipping linting
5:26:42 PM: - info Creating an optimized production build...
5:27:05 PM: (node:6217) [DEP_WEBPACK_MODULE_UPDATE_HASH] DeprecationWarning: Module.updateHash: Use new ChunkGraph API
5:27:05 PM: (Use `node --trace-deprecation ...` to show where the warning was created)
5:27:10 PM: - info Compiled successfully
5:27:10 PM: - info Collecting page data...
5:27:11 PM: Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
5:27:11 PM: In case this error is unexpected for you, please report it in https://pris.ly/prisma-prisma-bug-report

These are the full build logs:

5:25:47 PM: build-image version: ecdc8b770f4a0193fd3f258c1bc6029e681813a4 (focal)
5:25:47 PM: buildbot version: cf6afc7c389867a9137f0400977de947cd9bdd91
5:25:47 PM: Fetching cached dependencies
5:25:47 PM: Failed to fetch cache, continuing with build
5:25:47 PM: Starting to prepare the repo for build
5:25:47 PM: No cached dependencies found. Cloning fresh repo
5:25:47 PM: git clone --filter=blob:none https://github.com/Discriminology/report-card
5:25:48 PM: Preparing Git Reference refs/heads/main
5:25:50 PM: Custom publish path detected. Proceeding with the specified path: 'packages/app/.next'
5:25:50 PM: Custom functions path detected. Proceeding with the specified path: 'packages/app/netlify/functions'
5:25:50 PM: Custom build command detected. Proceeding with the specified command: 'pnpx prisma generate --schema prisma/schema.prisma && next build'
5:25:51 PM: Starting to install dependencies
5:25:51 PM: Python version set to 3.8
5:25:51 PM: Attempting Ruby version 2.7.2, read from environment
5:25:52 PM: Using Ruby version 2.7.2
5:25:52 PM: Started restoring cached go cache
5:25:52 PM: Finished restoring cached go cache
5:25:54 PM: go version go1.19.13 linux/amd64
5:25:54 PM: Using PHP version 8.0
5:25:56 PM: v18.20.4 is already installed.
5:25:57 PM: Now using node v18.20.4 (npm v10.7.0)
5:25:57 PM: Enabling Node.js Corepack
5:25:57 PM: Started restoring cached build plugins
5:25:57 PM: Finished restoring cached build plugins
5:25:57 PM: Started restoring cached corepack dependencies
5:25:57 PM: Finished restoring cached corepack dependencies
5:25:58 PM: pnpm workspaces detected
5:25:58 PM: Installing npm packages using pnpm version 8.15.8
5:25:58 PM:  WARN  The field "pnpm" was found in /opt/build/repo/packages/app/package.json. This will not take effect. You should configure "pnpm" at the root of the workspace instead.
5:25:58 PM: Scope: all 3 workspace projects
5:25:59 PM: ../..                                    | Progress: resolved 1, reused 0, downloaded 0, added 0
5:25:59 PM: ../..                                    |    +1994 ++++++++++++++++++++++++++++
5:26:00 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 0, added 0
5:26:01 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 176, added 175
5:26:02 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 374, added 371
5:26:03 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 583, added 582
5:26:04 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 809, added 807
5:26:05 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 1065, added 1045
5:26:06 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 1212, added 1207
5:26:07 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 1518, added 1516
5:26:08 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 1692, added 1690
5:26:09 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 1825, added 1810
5:26:10 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 1972, added 1963
5:26:11 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 1990, added 1989
5:26:11 PM: ../..                                    | Progress: resolved 1994, reused 0, downloaded 1994, added 1994, done
5:26:12 PM: .../node_modules/aws-sdk postinstall$ node scripts/warn-maintenance-mode.js
5:26:12 PM: .../node_modules/@prisma/engines postinstall$ node scripts/postinstall.js
5:26:12 PM: .../node_modules/aws-sdk postinstall: ╔═════════════════════════════════════════════════╗
5:26:12 PM: .../node_modules/aws-sdk postinstall: ║ The AWS SDK for JavaScript (v2) will reach      ║
5:26:12 PM: .../node_modules/aws-sdk postinstall: ║ -> maintenance mode on September 8, 2024.       ║
5:26:12 PM: .../node_modules/aws-sdk postinstall: ║ -> end-of-support on September 8, 2025.         ║
5:26:12 PM: .../node_modules/aws-sdk postinstall: ║                                                 ║
5:26:12 PM: .../node_modules/aws-sdk postinstall: ║ To continue receiving updates to AWS services,  ║
5:26:12 PM: .../node_modules/aws-sdk postinstall: ║ bug fixes, and security updates please upgrade  ║
5:26:12 PM: .../node_modules/aws-sdk postinstall: ║ to AWS SDK for JavaScript (v3).                 ║
5:26:12 PM: .../node_modules/aws-sdk postinstall: ║                                                 ║
5:26:12 PM: .../node_modules/aws-sdk postinstall: ║ More info: https://a.co/cUPnyil                 ║
5:26:12 PM: .../node_modules/aws-sdk postinstall: ╚═════════════════════════════════════════════════╝
5:26:12 PM: .../node_modules/aws-sdk postinstall: Done
5:26:12 PM: .../aws-crt@1.21.3/node_modules/aws-crt install$ node ./scripts/install.js
5:26:12 PM: .../aws-crt@1.21.3/node_modules/aws-crt install: The binding already exists, skip rebuilding. To rebuild the native addon, please run install.js with `--rebuild`
5:26:12 PM: .../aws-crt@1.21.3/node_modules/aws-crt install: Done
5:26:13 PM: .../node_modules/@prisma/engines postinstall: Done
5:26:13 PM: .../esbuild@0.18.13/node_modules/esbuild postinstall$ node install.js
5:26:13 PM: .../esbuild@0.18.20/node_modules/esbuild postinstall$ node install.js
5:26:13 PM: .../esbuild@0.18.13/node_modules/esbuild postinstall: Done
5:26:13 PM: .../prisma@5.9.1/node_modules/prisma preinstall$ node scripts/preinstall-entry.js
5:26:13 PM: .../esbuild@0.13.15/node_modules/esbuild postinstall$ node install.js
5:26:13 PM: .../esbuild@0.18.20/node_modules/esbuild postinstall: Done
5:26:13 PM: .../prisma@5.9.1/node_modules/prisma preinstall: Done
5:26:13 PM: .../esbuild@0.13.15/node_modules/esbuild postinstall: Done
5:26:13 PM: .../sharp@0.33.4/node_modules/sharp install$ node install/check
5:26:13 PM: .../node_modules/@prisma/client postinstall$ node scripts/postinstall.js
5:26:14 PM: .../node_modules/@prisma/client postinstall: prisma:warn We could not find your Prisma schema at `prisma/schema.prisma`.
5:26:14 PM: .../node_modules/@prisma/client postinstall: If you have a Prisma schema file in a custom path, you will need to run
5:26:14 PM: .../node_modules/@prisma/client postinstall: `prisma generate --schema=./path/to/your/schema.prisma` to generate Prisma Client.
5:26:14 PM: .../node_modules/@prisma/client postinstall: If you do not have a Prisma schema file yet, you can ignore this message.
5:26:14 PM: .../node_modules/@prisma/client postinstall: Done
5:26:15 PM: .../sharp@0.33.4/node_modules/sharp install: Done
5:26:16 PM: dependencies:
5:26:16 PM: + @algolia/autocomplete-js 1.12.1
5:26:16 PM: + @algolia/autocomplete-theme-classic 1.12.1
5:26:16 PM: + @aws-amplify/ui-react 6.1.3
5:26:16 PM: + @garystorey/slugify 1.0.3
5:26:16 PM: + @prisma/client 5.9.1
5:26:16 PM: + @raddix/use-scroll-spy 0.1.1
5:26:16 PM: + @types/react-instantsearch 6.10.4
5:26:16 PM: + @types/react-instantsearch-dom 6.12.7
5:26:16 PM: + algoliasearch 4.22.0
5:26:16 PM: + aws-amplify 6.0.16
5:26:16 PM: + classnames 2.2.6
5:26:16 PM: + color 3.2.1
5:26:16 PM: + next 13.4.19
5:26:16 PM: + react 18.2.0
5:26:16 PM: + react-circular-progressbar 2.0.3
5:26:16 PM: + react-dom 18.2.0
5:26:16 PM: + react-google-autocomplete 2.7.3
5:26:16 PM: + react-hook-form 7.47.0
5:26:16 PM: + react-icons 4.11.0
5:26:16 PM: + react-instantsearch 7.3.0
5:26:16 PM: + react-instantsearch-router-nextjs 7.6.0
5:26:16 PM: + react-modal-hook 3.0.2
5:26:16 PM: + react-toastify 9.1.3
5:26:16 PM: + react-tooltip 5.26.3
5:26:16 PM: + react-use 17.4.0
5:26:16 PM: + recharts 2.8.0
5:26:16 PM: + scroll-into-view-if-needed 3.1.0
5:26:16 PM: + sharp 0.33.4
5:26:16 PM: + superjson 1.13.3
5:26:16 PM: + swr 2.2.4
5:26:16 PM: + us-state-converter 1.0.6
5:26:16 PM: + zod 3.22.4
5:26:16 PM: devDependencies:
5:26:16 PM: + @faker-js/faker 8.1.0
5:26:16 PM: + @types/color 3.0.4
5:26:16 PM: + @types/react 18.2.23
5:26:16 PM: + @types/react-dom 18.2.8
5:26:16 PM: + dotenv 16.4.5
5:26:16 PM: + eslint 8.50.0
5:26:16 PM: + eslint-config-next 13.5.3
5:26:16 PM: + prisma 5.9.1
5:26:16 PM: + sass 1.56.1
5:26:16 PM: + ts-node 10.9.2
5:26:16 PM: + tsx 3.13.0
5:26:16 PM: + typescript 5.2.2
5:26:16 PM: . postinstall$ prisma generate
5:26:17 PM: . postinstall: Prisma schema loaded from prisma/schema.prisma
5:26:18 PM: . postinstall: ✔ Generated Prisma Client (v5.9.1) to ./../../node_modules/.prisma/client in 254ms
5:26:18 PM: . postinstall: Start using Prisma Client in Node.js (See: https://pris.ly/d/client)
5:26:18 PM: . postinstall: ```
. postinstall: import { PrismaClient } from '../../node_modules/.prisma/client'
5:26:18 PM: . postinstall: const prisma = new PrismaClient()
5:26:18 PM: . postinstall: ```
. postinstall: or start using Prisma Client at the edge (See: https://pris.ly/d/accelerate)
5:26:18 PM: . postinstall: ```
. postinstall: import { PrismaClient } from '../../node_modules/.prisma/client/edge'
5:26:18 PM: . postinstall: const prisma = new PrismaClient()
5:26:18 PM: . postinstall: ```
. postinstall: See other ways of importing Prisma Client: http://pris.ly/d/importing-client
5:26:18 PM: . postinstall: ┌─────────────────────────────────────────────────────────────┐
5:26:18 PM: . postinstall: │  Deploying your app to serverless or edge functions?        │
5:26:18 PM: . postinstall: │  Try Prisma Accelerate for connection pooling and caching.  │
5:26:18 PM: . postinstall: │  https://pris.ly/cli/accelerate                             │
5:26:18 PM: . postinstall: └─────────────────────────────────────────────────────────────┘
5:26:18 PM: . postinstall: Done
5:26:18 PM: Done in 19.5s
5:26:18 PM: npm packages installed using pnpm
5:26:19 PM: Successfully installed dependencies
5:26:19 PM: Starting build script
5:26:20 PM: Detected 1 framework(s)
5:26:20 PM: "next" at version "13.4.19"
5:26:20 PM: Section completed: initializing
5:26:22 PM: ​
5:26:22 PM: Netlify Build                                                 
5:26:22 PM: ────────────────────────────────────────────────────────────────
5:26:22 PM: ​
5:26:22 PM: ❯ Version
5:26:22 PM:   @netlify/build 29.53.0
5:26:22 PM: ​
5:26:22 PM: ❯ Flags
5:26:22 PM:   baseRelDir: true
5:26:22 PM:   buildId: 66b4f17b028d730008fd9562
5:26:22 PM:   deployId: 66b4f17b028d730008fd9564
5:26:22 PM: ​
5:26:22 PM: ❯ Current directory
5:26:22 PM:   /opt/build/repo/packages/app
5:26:22 PM: ​
5:26:22 PM: ❯ Config file
5:26:22 PM:   /opt/build/repo/packages/app/netlify.toml
5:26:22 PM: ​
5:26:22 PM: ❯ Context
5:26:22 PM:   production
5:26:34 PM: ​
5:26:34 PM: ❯ Using Next.js Runtime - v4.41.3
5:26:34 PM: ​
5:26:34 PM: ❯ Outdated plugins
5:26:34 PM:    - @netlify/plugin-nextjs@4.41.3: latest version is 5.6.0
5:26:34 PM:      To upgrade this plugin, please uninstall and re-install it from the Netlify plugins directory (https://app.netlify.com/plugins)
5:26:36 PM: No Next.js cache to restore.
5:26:36 PM: ​
5:26:36 PM: build.command from netlify.toml                               
5:26:36 PM: ────────────────────────────────────────────────────────────────
5:26:36 PM: ​
5:26:36 PM: $ pnpx prisma generate --schema prisma/schema.prisma && next build
5:26:37 PM: Progress: resolved 1, reused 0, downloaded 0, added 0
5:26:38 PM: Progress: resolved 3, reused 0, downloaded 3, added 0
5:26:39 PM: Packages: +6
5:26:39 PM: ++++++
5:26:39 PM: Progress: resolved 6, reused 0, downloaded 6, added 6, done
5:26:39 PM: .../node_modules/@prisma/engines postinstall$ node scripts/postinstall.js
5:26:39 PM: .../node_modules/@prisma/engines postinstall: Done
5:26:39 PM: .../prisma@5.18.0/node_modules/prisma preinstall$ node scripts/preinstall-entry.js
5:26:39 PM: .../prisma@5.18.0/node_modules/prisma preinstall: Done
5:26:40 PM: Prisma schema loaded from prisma/schema.prisma
5:26:41 PM: ✔ Generated Prisma Client (v5.9.1) to ./../../node_modules/.prisma/client in 263ms
5:26:41 PM: Start by importing your Prisma Client (See: http://pris.ly/d/importing-client)
5:26:41 PM: Tip: Curious about the SQL queries Prisma ORM generates? Optimize helps you enhance your visibility: https://pris.ly/tip-2-optimize
5:26:41 PM: warn Versions of prisma@5.18.0 and @prisma/client@5.9.1 don't match.
This might lead to unexpected behavior.
5:26:41 PM: Please make sure they have the same version.
5:26:42 PM: - warn No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
5:26:42 PM: - info Skipping validation of types
5:26:42 PM: - info Skipping linting
5:26:42 PM: - info Creating an optimized production build...
5:27:05 PM: (node:6217) [DEP_WEBPACK_MODULE_UPDATE_HASH] DeprecationWarning: Module.updateHash: Use new ChunkGraph API
5:27:05 PM: (Use `node --trace-deprecation ...` to show where the warning was created)
5:27:10 PM: - info Compiled successfully
5:27:10 PM: - info Collecting page data...
5:27:11 PM: Error: @prisma/client did not initialize yet. Please run "prisma generate" and try to import it again.
5:27:11 PM: In case this error is unexpected for you, please report it in https://pris.ly/prisma-prisma-bug-report
5:27:11 PM:     at new PrismaClient (/opt/build/repo/node_modules/.pnpm/@prisma+client@5.9.1_prisma@5.9.1/node_modules/.prisma/client/default.js:43:11)
5:27:11 PM:     at prismaClientSingleton (/opt/build/repo/packages/app/.next/server/chunks/961.js:24:12)
5:27:11 PM:     at 2961 (/opt/build/repo/packages/app/.next/server/chunks/961.js:26:37)
5:27:11 PM:     at __webpack_require__ (/opt/build/repo/packages/app/.next/server/webpack-runtime.js:25:42)
5:27:11 PM:     at /opt/build/repo/packages/app/.next/server/pages/school/[id].js:1677:69
5:27:11 PM:     at __webpack_require__.a (/opt/build/repo/packages/app/.next/server/webpack-runtime.js:89:13)
5:27:11 PM:     at 8370 (/opt/build/repo/packages/app/.next/server/pages/school/[id].js:1665:21)
5:27:11 PM:     at __webpack_require__ (/opt/build/repo/packages/app/.next/server/webpack-runtime.js:25:42)
5:27:11 PM:     at /opt/build/repo/packages/app/.next/server/pages/school/[id].js:33:90
5:27:11 PM:     at __webpack_require__.a (/opt/build/repo/packages/app/.next/server/webpack-runtime.js:89:13)
5:27:11 PM: > Build error occurred
5:27:11 PM: Error: Failed to collect page data for /school/[id]
5:27:11 PM:     at /opt/build/repo/node_modules/.pnpm/next@13.4.19_@babel+core@7.25.2_react-dom@18.2.0_react@18.2.0_sass@1.56.1/node_modules/next/dist/build/utils.js:1158:15 {
5:27:11 PM:   type: 'Error'
5:27:11 PM: }
5:27:11 PM: ​
5:27:11 PM: "build.command" failed                                        
5:27:11 PM: ────────────────────────────────────────────────────────────────
5:27:11 PM: ​
5:27:11 PM:   Error message
5:27:11 PM:   Command failed with exit code 1: pnpx prisma generate --schema prisma/schema.prisma && next build (https://ntl.fyi/exit-code-1)
5:27:11 PM: ​
5:27:11 PM:   Error location
5:27:11 PM:   In build.command from netlify.toml:
5:27:11 PM:   pnpx prisma generate --schema prisma/schema.prisma && next build
5:27:11 PM: ​
5:27:11 PM:   Resolved config
5:27:11 PM:   build:
5:27:11 PM:     base: /opt/build/repo/packages/app
5:27:11 PM:     command: pnpx prisma generate --schema prisma/schema.prisma && next build
5:27:11 PM:     commandOrigin: config
5:27:11 PM:     environment:
5:27:11 PM:       - DATABASE_URL
5:27:11 PM:       - NEXT_PUBLIC_ALGOLIA_APIKEY
5:27:11 PM:       - NEXT_PUBLIC_ALGOLIA_APPID
5:27:11 PM:       - NEXT_PUBLIC_API_URL
5:27:11 PM:       - NEXT_PUBLIC_MAPS_KEY
5:27:11 PM:       - PNPM_FLAGS
5:27:11 PM:       - GOOGLE_CLIENT_ID
5:27:11 PM:       - GOOGLE_CLIENT_SECRET
5:27:11 PM:       - NEXT_PUBLIC_COGNITO_REGION
5:27:11 PM:       - NEXT_PUBLIC_COGNITO_USER_POOL_ID
5:27:11 PM:       - NEXT_PUBLIC_COGNITO_USER_POOL_CLIENT_ID
5:27:11 PM:       - NEXT_PUBLIC_COGNITO_IDENTITY_POOL_ID
5:27:11 PM:       - NEXT_PRIVATE_TARGET
5:27:11 PM:     publish: /opt/build/repo/packages/app/.next
5:27:11 PM:     publishOrigin: ui
5:27:11 PM:   functionsDirectory: /opt/build/repo/packages/app/netlify/functions
5:27:11 PM:   plugins:
5:27:11 PM:     - inputs: {}
5:27:11 PM:       origin: ui
5:27:11 PM:       package: '@netlify/plugin-nextjs'
5:27:12 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
5:27:12 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:27:12 PM: Failing build: Failed to build site
5:27:12 PM: Finished processing build request in 1m25.295s

Looks like an issue caused due to how pnpm works: @prisma/client did not initialize yet when using PrismaClient in symlinked external package · Issue #21194 · prisma/prisma (github.com).

1 Like

this was the actual solution but your link helped lead me to it! Many thanks