Build works fine on my machine, fails on deploy

name: stalwart-dolphin-73ea68
log:

4:07:43 PM: build-image version: d7b3813f01c06610bc1723ff1b22446513ee7941 (focal)
4:07:43 PM: build-image tag: v4.14.3
4:07:43 PM: buildbot version: 4f669c94b322d52f143cdcbb17e55d40094aa06d
4:07:43 PM: Fetching cached dependencies
4:07:43 PM: Failed to fetch cache, continuing with build
4:07:43 PM: Starting to prepare the repo for build
4:07:44 PM: No cached dependencies found. Cloning fresh repo
4:07:44 PM: git clone https://github.com/bezlant/TheBiddingGame
4:07:44 PM: Preparing Git Reference refs/heads/develop
4:07:45 PM: Parsing package.json dependencies
4:07:46 PM: Section completed: initializing
4:07:46 PM: Starting build script
4:07:46 PM: Installing dependencies
4:07:46 PM: Python version set to 2.7
4:07:46 PM: Downloading and installing node v16.18.1...
4:07:47 PM: Downloading https://nodejs.org/dist/v16.18.1/node-v16.18.1-linux-x64.tar.xz...
4:07:47 PM: Computing checksum with sha256sum
4:07:47 PM: Checksums matched!
4:07:49 PM: Now using node v16.18.1 (npm v8.19.2)
4:07:49 PM: Enabling node corepack
4:07:49 PM: Started restoring cached build plugins
4:07:49 PM: Finished restoring cached build plugins
4:07:49 PM: Attempting ruby version 2.7.2, read from environment
4:07:50 PM: Using ruby version 2.7.2
4:07:50 PM: Using PHP version 8.0
4:07:50 PM: No npm workspaces detected
4:07:50 PM: Started restoring cached node modules
4:07:50 PM: Finished restoring cached node modules
4:07:51 PM: Installing NPM modules using NPM version 8.19.2
4:07:53 PM: npm WARN deprecated uuid@3.4.0: Please upgrade  to version 7 or higher.  Older versions may use Math.random() in certain circumstances, which is known to be problematic.  See https://v8.dev/blog/math-random for details.
4:07:53 PM: npm WARN deprecated mkdirp-promise@5.0.1: This package is broken and no longer maintained. 'mkdirp' itself supports promises now, please switch to that.
4:07:53 PM: npm WARN deprecated har-validator@5.1.5: this library is no longer supported
4:07:53 PM: npm WARN deprecated request@2.88.2: request has been deprecated, see https://github.com/request/request/issues/3142
4:07:53 PM: npm WARN deprecated multicodec@0.5.7: This module has been superseded by the multiformats module
4:07:54 PM: npm WARN deprecated multibase@0.6.1: This module has been superseded by the multiformats module
4:07:54 PM: npm WARN deprecated multicodec@1.0.4: This module has been superseded by the multiformats module
4:07:54 PM: npm WARN deprecated multibase@0.7.0: This module has been superseded by the multiformats module
4:07:54 PM: npm WARN deprecated cids@0.7.5: This module has been superseded by the multiformats module
4:07:57 PM: added 567 packages, and audited 568 packages in 6s
4:07:57 PM: 120 packages are looking for funding
4:07:57 PM:   run `npm fund` for details
4:07:57 PM: found 0 vulnerabilities
4:07:57 PM: NPM modules installed
4:07:57 PM: Creating package sha
4:07:57 PM: Started restoring cached go cache
4:07:57 PM: Finished restoring cached go cache
4:07:57 PM: Installing Go version 1.17 (requested 1.17)
4:08:02 PM: unset GOOS;
4:08:02 PM: unset GOARCH;
4:08:02 PM: export GOROOT='/opt/buildhome/.gimme/versions/go1.17.linux.amd64';
4:08:02 PM: export PATH="/opt/buildhome/.gimme/versions/go1.17.linux.amd64/bin:${PATH}";
4:08:02 PM: go version >&2;
4:08:02 PM: export GIMME_ENV="/opt/buildhome/.gimme/env/go1.17.linux.amd64.env"
4:08:02 PM: go version go1.17 linux/amd64
4:08:02 PM: Detected 1 framework(s)
4:08:02 PM: "next" at version "13.0.3"
4:08:02 PM: Installing missing commands
4:08:02 PM: Verify run directory
4:08:03 PM: ​
4:08:03 PM: ────────────────────────────────────────────────────────────────
4:08:03 PM:   Netlify Build                                                 
4:08:03 PM: ────────────────────────────────────────────────────────────────
4:08:03 PM: ​
4:08:03 PM: ❯ Version
4:08:03 PM:   @netlify/build 28.1.13
4:08:03 PM: ​
4:08:03 PM: ❯ Flags
4:08:03 PM:   baseRelDir: true
4:08:03 PM:   buildId: 637a269e2514fc000824edc2
4:08:03 PM:   deployId: 637a269e2514fc000824edc4
4:08:03 PM: ​
4:08:03 PM: ❯ Current directory
4:08:03 PM:   /opt/build/repo
4:08:03 PM: ​
4:08:03 PM: ❯ Config file
4:08:03 PM:   No config file was defined: using default values.
4:08:03 PM: ​
4:08:03 PM: ❯ Context
4:08:03 PM:   production
4:08:03 PM: ​
4:08:03 PM: ❯ Installing plugins
4:08:03 PM:    - @netlify/plugin-nextjs@4.29.1
4:08:11 PM: ​
4:08:11 PM: ❯ Using Next.js Runtime - v4.29.1
4:08:12 PM: ​
4:08:12 PM: ────────────────────────────────────────────────────────────────
4:08:12 PM:   1. @netlify/plugin-nextjs (onPreBuild event)                  
4:08:12 PM: ────────────────────────────────────────────────────────────────
4:08:12 PM: ​
4:08:12 PM: No Next.js cache to restore.
4:08:12 PM: Netlify configuration property "build.environment.NEXT_PRIVATE_TARGET" value changed.
4:08:12 PM: ​
4:08:12 PM: (@netlify/plugin-nextjs onPreBuild completed in 15ms)
4:08:12 PM: ​
4:08:12 PM: ────────────────────────────────────────────────────────────────
4:08:12 PM:   2. Build command from Netlify app                             
4:08:12 PM: ────────────────────────────────────────────────────────────────
4:08:12 PM: ​
4:08:12 PM: $ npm run build
4:08:12 PM: > my-app@0.1.0 build
4:08:12 PM: > next build
4:08:13 PM: warn  - No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
4:08:13 PM: info  - Linting and checking validity of types...
4:08:14 PM: info  - Creating an optimized production build...
4:08:19 PM: info  - Compiled successfully
4:08:19 PM: info  - Collecting page data...
4:08:24 PM: info  - Generating static pages (0/3)
4:08:24 PM: TypeError: Cannot set property Request of #<Object> which has only a getter
4:08:24 PM:     at /opt/build/repo/node_modules/abortcontroller-polyfill/dist/polyfill-patch-fetch.js:529:18
4:08:24 PM:     at /opt/build/repo/node_modules/abortcontroller-polyfill/dist/polyfill-patch-fetch.js:542:5
4:08:24 PM:     at /opt/build/repo/node_modules/abortcontroller-polyfill/dist/polyfill-patch-fetch.js:3:3
4:08:24 PM:     at Object.<anonymous> (/opt/build/repo/node_modules/abortcontroller-polyfill/dist/polyfill-patch-fetch.js:4:3)
4:08:24 PM:     at Module._compile (node:internal/modules/cjs/loader:1155:14)
4:08:24 PM:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
4:08:24 PM:     at Module.load (node:internal/modules/cjs/loader:1033:32)
4:08:24 PM:     at Function.Module._load (node:internal/modules/cjs/loader:868:12)
4:08:24 PM:     at Module.require (node:internal/modules/cjs/loader:1057:19)
4:08:24 PM:     at require (node:internal/modules/cjs/helpers:103:18)
4:08:24 PM: Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
4:08:24 PM: TypeError: Cannot set property Request of #<Object> which has only a getter
4:08:24 PM:     at /opt/build/repo/node_modules/abortcontroller-polyfill/dist/polyfill-patch-fetch.js:529:18
4:08:24 PM:     at /opt/build/repo/node_modules/abortcontroller-polyfill/dist/polyfill-patch-fetch.js:542:5
4:08:24 PM:     at /opt/build/repo/node_modules/abortcontroller-polyfill/dist/polyfill-patch-fetch.js:3:3
4:08:24 PM:     at Object.<anonymous> (/opt/build/repo/node_modules/abortcontroller-polyfill/dist/polyfill-patch-fetch.js:4:3)
4:08:24 PM:     at Module._compile (node:internal/modules/cjs/loader:1155:14)
4:08:24 PM:     at Object.Module._extensions..js (node:internal/modules/cjs/loader:1209:10)
4:08:24 PM:     at Module.load (node:internal/modules/cjs/loader:1033:32)
4:08:24 PM:     at Function.Module._load (node:internal/modules/cjs/loader:868:12)
4:08:24 PM:     at Module.require (node:internal/modules/cjs/loader:1057:19)
4:08:24 PM:     at require (node:internal/modules/cjs/helpers:103:18)
4:08:24 PM: info  - Generating static pages (3/3)
4:08:24 PM: > Build error occurred
4:08:24 PM: Error: Export encountered errors on following paths:
4:08:24 PM: 	/
4:08:24 PM:     at /opt/build/repo/node_modules/next/dist/export/index.js:408:19
4:08:24 PM:     at runMicrotasks (<anonymous>)
4:08:24 PM:     at processTicksAndRejections (node:internal/process/task_queues:96:5)
4:08:24 PM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
4:08:24 PM:     at async /opt/build/repo/node_modules/next/dist/build/index.js:1331:21
4:08:24 PM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
4:08:24 PM:     at async /opt/build/repo/node_modules/next/dist/build/index.js:1191:17
4:08:24 PM:     at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
4:08:24 PM:     at async Object.build [as default] (/opt/build/repo/node_modules/next/dist/build/index.js:65:29)
4:08:25 PM: ​
4:08:25 PM: ────────────────────────────────────────────────────────────────
4:08:25 PM:   "build.command" failed                                        
4:08:25 PM: ────────────────────────────────────────────────────────────────
4:08:25 PM: ​
4:08:25 PM:   Error message
4:08:25 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
4:08:25 PM: ​
4:08:25 PM:   Error location
4:08:25 PM:   In Build command from Netlify app:
4:08:25 PM:   npm run build
4:08:26 PM: Creating deploy upload records
4:08:25 PM: ​
4:08:25 PM:   Resolved config
4:08:25 PM:   build:
4:08:25 PM:     command: npm run build
4:08:26 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
4:08:25 PM:     commandOrigin: ui
4:08:25 PM:     environment:
4:08:25 PM:       - NEXT_PRIVATE_TARGET
4:08:25 PM:     publish: /opt/build/repo/.next
4:08:25 PM:     publishOrigin: ui
4:08:25 PM:   plugins:
4:08:25 PM:     - inputs: {}
4:08:25 PM:       origin: ui
4:08:25 PM:       package: '@netlify/plugin-nextjs'
4:08:25 PM: Caching artifacts
4:08:25 PM: Started saving node modules
4:08:25 PM: Finished saving node modules
4:08:25 PM: Started saving build plugins
4:08:25 PM: Finished saving build plugins
4:08:25 PM: Started saving pip cache
4:08:25 PM: Finished saving pip cache
4:08:25 PM: Started saving emacs cask dependencies
4:08:25 PM: Finished saving emacs cask dependencies
4:08:25 PM: Started saving maven dependencies
4:08:25 PM: Finished saving maven dependencies
4:08:25 PM: Started saving boot dependencies
4:08:25 PM: Finished saving boot dependencies
4:08:25 PM: Started saving rust rustup cache
4:08:25 PM: Finished saving rust rustup cache
4:08:25 PM: Started saving go dependencies
4:08:25 PM: Finished saving go dependencies
4:08:26 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
4:08:26 PM: Failing build: Failed to build site
4:08:26 PM: Finished processing build request in 42.935180936s

Your build has some type errors, which is related to your code. This is not a Netlify issue and you’d have to check your codebase to fix this.

Any recommendations? I have successfully built on my OSX machine & Arch Linux machine.
What is the best way to fix it? My build is simply create-next-app :open_mouth:
The errors are somewhere in node module pollyfills. No idea what it even is…

I would find it really surprising if it builds as it is locally. Mind sharing a reproduction?

bug
Here is the repo https://github.com/bezlant/TheBiddingGame

I got the same error locally on my macOS:

Thank you for helping me. I did a plenty of research this morning an stumbled upon this issue on nextjs git and found a solution.
If anyone gets this problem you simply need to specify a node-version.
By default netlify uses node v16, I set it to v19 and works like a charm. (I have v19 on my PC)