Build Error During Initial Deployment

Hi everyone,
I’m trying to deploy a new website, and the build log returns the below error message:

3:06:51 PM: Netlify Build
3:06:51 PM: ────────────────────────────────────────────────────────────────
3:06:51 PM: ​
3:06:51 PM: ❯ Version
3:06:51 PM: @netlify/build 29.46.5
3:06:51 PM: ​
3:06:51 PM: ❯ Flags
3:06:51 PM: baseRelDir: true
3:06:51 PM: buildId: 6667787838c6f35c95afc50e
3:06:51 PM: deployId: 6667787838c6f35c95afc510
3:06:51 PM: ​
3:06:51 PM: ❯ Current directory
3:06:51 PM: /opt/build/repo
3:06:51 PM: ​
3:06:51 PM: ❯ Config file
3:06:51 PM: /opt/build/repo/netlify.toml
3:06:51 PM: ​
3:06:51 PM: ❯ Context
3:06:51 PM: production
3:06:53 PM: ​
3:06:53 PM: ❯ Using Next.js Runtime - v5.3.2
3:06:54 PM: No Next.js cache to restore
3:06:54 PM: ​
3:06:54 PM: Build command from Netlify app
3:06:54 PM: ────────────────────────────────────────────────────────────────
3:06:54 PM: ​
3:06:54 PM: $ npm run build
3:06:54 PM: > airbnb-clone-2@0.1.0 build
3:06:54 PM: > next build
3:06:55 PM: :warning: No build cache found. Please configure build caching for faster rebuilds. Read more: No Cache Detected | Next.js
3:06:55 PM: ▲ Next.js 14.1.4
3:06:55 PM: - Environments: .env
3:06:55 PM: Creating an optimized production build …
3:07:20 PM: ✓ Compiled successfully
3:07:20 PM: Linting and checking validity of types …
3:07:21 PM: ./app/components/modals/RentModal.tsx
3:07:21 PM: 69:5 Warning: React Hook useMemo has an unnecessary dependency: ‘location’. Either exclude it or remove the dependency array. react-hooks/exhaustive-deps
3:07:21 PM: ./app/components/modals/SearchModal.tsx
3:07:21 PM: 41:9 Warning: React Hook useMemo has an unnecessary dependency: ‘location’. Either exclude it or remove the dependency array. react-hooks/exhaustive-deps
3:07:21 PM: 87:8 Warning: React Hook useCallback has missing dependencies: ‘location?.value’ and ‘router’. Either include them or remove the dependency array. react-hooks/exhaustive-deps
3:07:21 PM: info - Need to disable some ESLint rules? Learn more here: Configuring: ESLint | Next.js
3:07:23 PM: Collecting page data …
3:07:24 PM: Prisma has detected that this project was built on Netlify CI, 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.
3:07:24 PM: Learn how: Learn to configure your build process on Netlify to avoid caching-related problems | Prisma Documentation
3:07:24 PM: PrismaClientInitializationError: Prisma has detected that this project was built on Netlify CI, 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.
3:07:24 PM: Learn how: Learn to configure your build process on Netlify to avoid caching-related problems | Prisma Documentation
3:07:24 PM: at ma (/opt/build/repo/node_modules/@prisma/client/runtime/library.js:33:69)
3:07:24 PM: at new r (/opt/build/repo/node_modules/@prisma/client/runtime/library.js:127:3083)
3:07:24 PM: at 66792 (/opt/build/repo/.next/server/app/api/reservations/route.js:1:3371)
3:07:24 PM: at t (/opt/build/repo/.next/server/webpack-runtime.js:1:128)
3:07:24 PM: at 4683 (/opt/build/repo/.next/server/app/api/reservations/route.js:1:1213)
3:07:24 PM: at t (/opt/build/repo/.next/server/webpack-runtime.js:1:128)
3:07:24 PM: at t (/opt/build/repo/.next/server/app/api/reservations/route.js:1:3453)
3:07:24 PM: at /opt/build/repo/.next/server/app/api/reservations/route.js:1:3488
3:07:24 PM: at t.X (/opt/build/repo/.next/server/webpack-runtime.js:1:1206)
3:07:24 PM: at /opt/build/repo/.next/server/app/api/reservations/route.js:1:3466 {
3:07:24 PM: clientVersion: ‘5.14.0’,
3:07:24 PM: errorCode: undefined
3:07:24 PM: }
3:07:24 PM: > Build error occurred
3:07:24 PM: Error: Failed to collect page data for /api/reservations
3:07:24 PM: at /opt/build/repo/node_modules/next/dist/build/utils.js:1258:15
3:07:24 PM: at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
3:07:24 PM: type: ‘Error’
3:07:24 PM: }
3:07:25 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2 (Search results for '"non-zero exit code: 2"' - Netlify Support Forums)
3:07:25 PM: ​
3:07:25 PM: “build.command” failed
3:07:25 PM: ────────────────────────────────────────────────────────────────
3:07:25 PM: ​
3:07:25 PM: Error message
3:07:25 PM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
3:07:25 PM: ​
3:07:25 PM: Error location
3:07:25 PM: In Build command from Netlify app:
3:07:25 PM: npm run build
3:07:25 PM: ​
3:07:25 PM: Resolved config
3:07:25 PM: build:
3:07:25 PM: command: npm run build
3:07:25 PM: commandOrigin: ui
3:07:25 PM: environment:
3:07:25 PM: - DATABASE_URL
3:07:25 PM: - GITHUB_ID
3:07:25 PM: - GITHUB_SECRET
3:07:25 PM: - GOOGLE_CLIENT_ID
3:07:25 PM: - GOOGLE_CLIENT_SECRET
3:07:25 PM: - ****
3:07:25 PM: - NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
3:07:25 PM: - PRISMA_TELEMETRY_INFORMATION
3:07:25 PM: publish: /opt/build/repo/.next
3:07:25 PM: publishOrigin: ui
3:07:25 PM: plugins:
3:07:25 PM: - inputs: {}
3:07:25 PM: origin: ui
3:07:25 PM: package: ‘@netlify/plugin-nextjs’
3:07:25 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
3:07:25 PM: Failing build: Failed to build site
3:07:26 PM: Finished processing build request in 1m7.359s

Hey there @shreem

This part is pretty interesting here:

Error: Failed to collect page data for /api/reservations

Does this work locally?

Alternatively I noticed a few other things:

3:07:21 PM: 69:5 Warning: React Hook useMemo has an unnecessary dependency: ‘location’. Either exclude it or remove the dependency array. react-hooks/exhaustive-deps
3:07:21 PM: ./app/components/modals/SearchModal.tsx
3:07:21 PM: 41:9 Warning: React Hook useMemo has an unnecessary dependency: ‘location’. Either exclude it or remove the dependency array. react-hooks/exhaustive-deps
3:07:21 PM: 87:8 Warning: React Hook useCallback has missing dependencies: ‘location?.value’ and ‘router’. Either include them or remove the dependency array. react-hooks/exhaustive-deps

Adding CI=npm run build to your netlify.toml, or as your build command should skip these. Example:

[build]
command = "CI= npm run build"

One last thing I noticed that’s a bit odd, and I did some researching on, but not entirely confident on is this bit:

3:07:24 PM: PrismaClientInitializationError: Prisma has detected that this project was built on Netlify CI, 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.

It looks like the error is telling you to add prisma generate to your build command, so the Prisma client can work properly. Something like this should do the trick:

[build]
command = "prisma generate && npm run build"

Ok, so I have made these changes. Here is my updated netlify.toml:

[build]
  dependencies = ["prisma"]
  environment = { PRISMA_TELEMETRY_INFORMATION = "false" }
  command = "prisma generate && npm run build"

However, I get a new error. Here is the build log:

9:12:02 PM: Netlify Build                                                 
9:12:02 PM: ────────────────────────────────────────────────────────────────
9:12:02 PM: ​
9:12:02 PM: ❯ Version
9:12:02 PM:   @netlify/build 29.46.5
9:12:02 PM: ​
9:12:02 PM: ❯ Flags
9:12:02 PM:   baseRelDir: true
9:12:02 PM:   buildId: 6667ce665e2a840008c39973
9:12:02 PM:   deployId: 6667ce665e2a840008c39975
9:12:02 PM: ​
9:12:02 PM: ❯ Current directory
9:12:02 PM:   /opt/build/repo
9:12:02 PM: ​
9:12:02 PM: ❯ Config file
9:12:02 PM:   /opt/build/repo/netlify.toml
9:12:02 PM: ​
9:12:02 PM: ❯ Context
9:12:02 PM:   production
9:12:03 PM: ​
9:12:03 PM: ❯ Using Next.js Runtime - v5.3.2
9:12:04 PM: No Next.js cache to restore
9:12:04 PM: ​
9:12:04 PM: build.command from netlify.toml                               
9:12:04 PM: ────────────────────────────────────────────────────────────────
9:12:04 PM: ​
9:12:04 PM: $ prisma generate && npm run build
9:12:05 PM: Environment variables loaded from .env
9:12:05 PM: Prisma schema loaded from prisma/schema.prisma
9:12:05 PM: ✔ Generated Prisma Client (v5.14.0) to ./node_modules/@prisma/client in 72ms
9:12:05 PM: Start using Prisma Client in Node.js (See: https://pris.ly/d/client)
9:12:05 PM: ```
import { PrismaClient } from '@prisma/client'
const prisma = new PrismaClient()

9:12:05 PM: or start using Prisma Client at the edge (See: What is Accelerate | Prisma Documentation)
9:12:05 PM: ```
import { PrismaClient } from ‘@prisma/client/edge’
const prisma = new PrismaClient()

9:12:05 PM: See other ways of importing Prisma Client: http://pris.ly/d/importing-client
9:12:05 PM: ┌─────────────────────────────────────────────────────────────┐
9:12:05 PM: │  Deploying your app to serverless or edge functions?        │
9:12:05 PM: │  Try Prisma Accelerate for connection pooling and caching.  │
9:12:05 PM: │  https://pris.ly/cli/--accelerate                           │
9:12:05 PM: └─────────────────────────────────────────────────────────────┘
9:12:06 PM: > airbnb-clone-2@0.1.0 build
9:12:06 PM: > next build
9:12:06 PM: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
9:12:06 PM:    ▲ Next.js 14.1.4
9:12:06 PM:    - Environments: .env
9:12:06 PM:    Creating an optimized production build ...
9:12:32 PM:  ✓ Compiled successfully
9:12:32 PM:    Linting and checking validity of types ...
9:12:34 PM: ./app/components/modals/RentModal.tsx
9:12:34 PM: 69:5  Warning: React Hook useMemo has an unnecessary dependency: 'location'. Either exclude it or remove the dependency array.  react-hooks/exhaustive-deps
9:12:34 PM: ./app/components/modals/SearchModal.tsx
9:12:34 PM: 41:9  Warning: React Hook useMemo has an unnecessary dependency: 'location'. Either exclude it or remove the dependency array.  react-hooks/exhaustive-deps
9:12:34 PM: 87:8  Warning: React Hook useCallback has missing dependencies: 'location?.value' and 'router'. Either include them or remove the dependency array.  react-hooks/exhaustive-deps
9:12:34 PM: info  - Need to disable some ESLint rules? Learn more here: https://nextjs.org/docs/basic-features/eslint#disabling-rules
9:12:35 PM:    Collecting page data ...
9:12:38 PM:    Generating static pages (0/12) ...
9:12:39 PM:    Generating static pages (3/12)
9:12:39 PM: Error: Error: Dynamic server usage: Page couldn't be rendered statically because it used `searchParams.userId`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
    at i (/opt/build/repo/.next/server/app/page.js:1:6294)
9:12:39 PM:     at u (/opt/build/repo/.next/server/app/page.js:1:7040)
9:12:39 PM:     at em (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:131205)
9:12:39 PM:     at /opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142906
9:12:39 PM:     at Array.toJSON (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:146484)
9:12:39 PM:     at stringify (<anonymous>)
9:12:39 PM:     at eR (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:134868)
9:12:39 PM:     at eP (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135311)
9:12:39 PM:     at AsyncLocalStorage.run (node:async_hooks:338:14)
9:12:39 PM:     at Timeout._onTimeout (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:146936)
9:12:39 PM: Error: Error: Dynamic server usage: Page couldn't be rendered statically because it used `searchParams.userId`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
    at i (/opt/build/repo/.next/server/app/page.js:1:6294)
9:12:39 PM:     at u (/opt/build/repo/.next/server/app/page.js:1:7040)
9:12:39 PM:     at em (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:131205)
9:12:39 PM:     at /opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142906
9:12:39 PM:     at Array.toJSON (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:146484)
9:12:39 PM:     at stringify (<anonymous>)
9:12:39 PM:     at eR (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:134868)
9:12:39 PM:     at eP (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135311)
9:12:39 PM:     at Timeout._onTimeout (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:132091)
9:12:39 PM:     at listOnTimeout (node:internal/timers:569:17)
9:12:39 PM: Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
9:12:39 PM: Error: Error: Dynamic server usage: Page couldn't be rendered statically because it used `searchParams.userId`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
    at i (/opt/build/repo/.next/server/app/page.js:1:6294)
9:12:39 PM:     at u (/opt/build/repo/.next/server/app/page.js:1:7040)
9:12:39 PM:     at em (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:131205)
9:12:39 PM:     at /opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:142906
9:12:39 PM:     at Array.toJSON (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:146484)
9:12:39 PM:     at stringify (<anonymous>)
9:12:39 PM:     at eR (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:134868)
9:12:39 PM:     at eP (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:135311)
9:12:39 PM:     at AsyncLocalStorage.run (node:async_hooks:338:14)
9:12:39 PM:     at Timeout._onTimeout (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:146936)
9:12:39 PM:    Generating static pages (6/12)
9:12:39 PM:    Generating static pages (9/12)
9:12:39 PM:  ✓ Generating static pages (12/12)
9:12:39 PM: > Export encountered errors on following paths:
9:12:39 PM: 	/page: /
9:12:39 PM: ​
9:12:39 PM: "build.command" failed                                        
9:12:39 PM: ────────────────────────────────────────────────────────────────
9:12:39 PM: ​
9:12:39 PM:   Error message
9:12:39 PM:   Command failed with exit code 1: prisma generate && npm run build (https://ntl.fyi/exit-code-1)
9:12:39 PM: ​
9:12:39 PM:   Error location
9:12:39 PM:   In build.command from netlify.toml:
9:12:39 PM:   prisma generate && npm run build
9:12:39 PM: ​
9:12:39 PM:   Resolved config
9:12:39 PM:   build:
9:12:39 PM:     command: prisma generate && npm run build
9:12:39 PM:     commandOrigin: config
9:12:39 PM:     environment:
9:12:39 PM:       - DATABASE_URL
9:12:39 PM:       - GITHUB_ID
9:12:39 PM:       - GITHUB_SECRET
9:12:39 PM:       - GOOGLE_CLIENT_ID
9:12:39 PM:       - GOOGLE_CLIENT_SECRET
9:12:39 PM:       - ****
9:12:39 PM:       - NEXT_PUBLIC_CLOUDINARY_CLOUD_NAME
9:12:39 PM:       - PRISMA_TELEMETRY_INFORMATION
9:12:39 PM:     publish: /opt/build/repo/.next
9:12:39 PM:     publishOrigin: ui
9:12:39 PM:   plugins:
9:12:39 PM:     - inputs: {}
9:12:39 PM:       origin: ui
9:12:39 PM:       package: '@netlify/plugin-nextjs'
9:12:40 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
9:12:40 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:12:40 PM: Failing build: Failed to build site
9:12:40 PM: Finished processing build request in 1m10.666s

To clarify, we have to make the netlify.toml in our root directory ourselves, right? Also, to answer your question, this has been coded on my computer and I have used localhost for developing it. I have committed it to GitHub and then fed that to Netlify. I did not have my local server running.

Not sure what this is. That’s not a valid property (it doesn’t cause any errors, but it also doesn’t do anything).

As for the error, did you check: Dynamic server usage: Page couldn't be rendered statically because it used `nextUrl.searchParams` in Next.js version 14 - Stack Overflow or Dynamic server usage: Page couldn’t be rendered statically because it used cookies · Issue #56630 · vercel/next.js (github.com)?