Issue with building next.js app. Build logs included. Im pretty stuck here and need some help

This is my current build log. I have spent time removing unnecessary pages that were causing the first document not defined issues. Now that those are removed I get only one error as you can see below. Also added the CI= npm run build, but its still not building. Not sure what to do here and could really use some help.

7:16:26 PM: Waiting for other deploys from your team to complete. Check the queue: Netlify
7:17:27 PM: build-image version: 006dca901dab83234b4881f914ac1a189ff41daa (focal)
7:17:27 PM: buildbot version: e8a1f877a96ee9d2b754bae26acb6bb322cba939
7:17:27 PM: Fetching cached dependencies
7:17:27 PM: Failed to fetch cache, continuing with build
7:17:27 PM: Starting to prepare the repo for build
7:17:27 PM: No cached dependencies found. Cloning fresh repo
7:17:27 PM: git clone --filter=blob:none https://github.com/username
7:17:28 PM: Preparing Git Reference refs/heads/main
7:17:29 PM: Custom build path detected. Proceeding with the specified path: ‘’
7:17:30 PM: Starting to install dependencies
7:17:30 PM: Python version set to 3.8
7:17:30 PM: Attempting Ruby version 2.7.2, read from environment
7:17:31 PM: Using Ruby version 2.7.2
7:17:32 PM: Started restoring cached go cache
7:17:32 PM: Finished restoring cached go cache
7:17:33 PM: go version go1.19.13 linux/amd64
7:17:34 PM: Using PHP version 8.0
7:17:36 PM: Downloading and installing node v20.15.1…
7:17:36 PM: Downloading https://nodejs.org/dist/v20.15.1/node-v20.15.1-linux-x64.tar.xz
7:17:36 PM: Computing checksum with sha256sum
7:17:36 PM: Checksums matched!
7:17:38 PM: Now using node v20.15.1 (npm v10.7.0)
7:17:38 PM: Enabling Node.js Corepack
7:17:38 PM: Started restoring cached build plugins
7:17:38 PM: Finished restoring cached build plugins
7:17:38 PM: Started restoring cached corepack dependencies
7:17:38 PM: Finished restoring cached corepack dependencies
7:17:38 PM: No npm workspaces detected
7:17:38 PM: Started restoring cached node modules
7:17:38 PM: Finished restoring cached node modules
7:17:39 PM: Installing npm packages using npm version 10.7.0
7:17:46 PM: added 374 packages, and audited 375 packages in 8s
7:17:46 PM: 131 packages are looking for funding
7:17:46 PM: run npm fund for details
7:17:46 PM: found 0 vulnerabilities
7:17:46 PM: npm packages installed
7:17:46 PM: Successfully installed dependencies
7:17:47 PM: Starting build script
7:17:48 PM: Detected 1 framework(s)
7:17:48 PM: “next” at version “14.2.3”
7:17:48 PM: Section completed: initializing
7:17:49 PM: ​
7:17:49 PM: Netlify Build
7:17:49 PM: ────────────────────────────────────────────────────────────────
7:17:49 PM: ​
7:17:49 PM: ❯ Version
7:17:49 PM: @netlify/build 29.50.5
7:17:49 PM: ​
7:17:49 PM: ❯ Flags
7:17:49 PM: baseRelDir: true
7:17:49 PM: buildId: 668f407abf74b2000897ee39
7:17:49 PM: deployId: 668f407abf74b2000897ee3b
7:17:49 PM: ​
7:17:49 PM: ❯ Current directory
7:17:49 PM: /opt/build/repo
7:17:49 PM: ​
7:17:49 PM: ❯ Config file
7:17:49 PM: No config file was defined: using default values.
7:17:49 PM: ​
7:17:49 PM: ❯ Context
7:17:49 PM: production
7:17:50 PM: ​
7:17:50 PM: ❯ Using Next.js Runtime - v5.5.1
7:17:52 PM: No Next.js cache to restore
7:17:52 PM: ​
7:17:52 PM: Build command from Netlify app
7:17:52 PM: ────────────────────────────────────────────────────────────────
7:17:52 PM: ​
7:17:52 PM: $ CI= npm run build
7:17:52 PM: > funto-nextjs@0.1.0 build
7:17:52 PM: > next build
7:17:52 PM: :warning: No build cache found. Please configure build caching for faster rebuilds. Read more: No Cache Detected | Next.js
7:17:52 PM: ▲ Next.js 14.2.3
7:17:52 PM: Creating an optimized production build …
7:18:05 PM: ✓ Compiled successfully
7:18:05 PM: Skipping linting
7:18:05 PM: Checking validity of types …
7:18:12 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)
7:18:09 PM: Collecting page data …
7:18:11 PM: Generating static pages (0/8) …
7:18:11 PM: Generating static pages (2/8)
7:18:11 PM: Generating static pages (4/8)
7:18:11 PM: Generating static pages (6/8)
7:18:11 PM: ReferenceError: document is not defined
7:18:11 PM: at G (/opt/build/repo/.next/server/app/page.js:1:31734)
7:18:11 PM: at s (/opt/build/repo/.next/server/app/page.js:1:32562)
7:18:11 PM: at 5747 (/opt/build/repo/.next/server/app/page.js:1:81573)
7:18:11 PM: at t (/opt/build/repo/.next/server/webpack-runtime.js:1:128)
7:18:11 PM: at 7891 (/opt/build/repo/.next/server/app/page.js:1:115154)
7:18:11 PM: at Object.t [as require] (/opt/build/repo/.next/server/webpack-runtime.js:1:128)
7:18:11 PM: at require (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:18365)
7:18:11 PM: at I (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:94362)
7:18:11 PM: at C (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:92913)
7:18:11 PM: at rP (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:33974) {
7:18:11 PM: digest: ‘3155171339’
7:18:11 PM: }
7:18:11 PM: Error occurred prerendering page “/”. Read more: Prerender Error | Next.js
7:18:11 PM: ReferenceError: document is not defined
7:18:11 PM: at G (/opt/build/repo/.next/server/app/page.js:1:31734)
7:18:11 PM: at s (/opt/build/repo/.next/server/app/page.js:1:32562)
7:18:11 PM: at 5747 (/opt/build/repo/.next/server/app/page.js:1:81573)
7:18:11 PM: at t (/opt/build/repo/.next/server/webpack-runtime.js:1:128)
7:18:11 PM: at 7891 (/opt/build/repo/.next/server/app/page.js:1:115154)
7:18:11 PM: at Object.t [as require] (/opt/build/repo/.next/server/webpack-runtime.js:1:128)
7:18:11 PM: at require (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:18365)
7:18:11 PM: at I (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:94362)
7:18:11 PM: at C (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:92913)
7:18:11 PM: at rP (/opt/build/repo/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:33974)
7:18:11 PM: ✓ Generating static pages (8/8)
7:18:11 PM: > Export encountered errors on following paths:
7:18:11 PM: /page: /
7:18:11 PM: ​
7:18:11 PM: “build.command” failed
7:18:11 PM: ────────────────────────────────────────────────────────────────
7:18:11 PM: ​
7:18:11 PM: Error message
7:18:11 PM: Command failed with exit code 1: CI= npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
7:18:11 PM: ​
7:18:11 PM: Error location
7:18:11 PM: In Build command from Netlify app:
7:18:11 PM: CI= npm run build
7:18:11 PM: ​
7:18:11 PM: Resolved config
7:18:11 PM: build:
7:18:11 PM: base: /opt/build/repo
7:18:11 PM: command: CI= npm run build
7:18:11 PM: commandOrigin: ui
7:18:11 PM: publish: /opt/build/repo/.next
7:18:11 PM: publishOrigin: ui
7:18:11 PM: plugins:
7:18:11 PM: - inputs: {}
7:18:11 PM: origin: ui
7:18:11 PM: package: ‘@netlify/plugin-nextjs’
7:18:12 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
7:18:12 PM: Failing build: Failed to build site
7:18:12 PM: Finished processing build request in 45.379s

@error The relevant error is:

The issue is that it’s trying to access document and that doesn’t exist.

If you look at the help documentation that Next has output:
https://nextjs.org/docs/messages/prerender-error

It mentions:

You could investigate that, or adjust the code so it doesn’t try to access document.

This only adjusts the default behavior so that warnings aren’t treated as errors.
It’s not a magic solution for getting past actual build errors, which is what you’re currently experiencing.

Thanks for getting back to me so fast. Really appreciate it. I spent quite a bit of time disabling server-side rendering on nearly all pages, since errors came up for all in the beginning. All I had to do was disable it on the home page and all good, apparently I missed the most important page :rofl:. Successful build, thank god, been at this all day lol.

Thanks again