How to solve this build error from this error message what do you guys infer?

website : https://enchanting-lily-65218d.netlify.app/

10:14:37 PM: build-image version: 9e9fc1674276da9a9f2d77b89f9d9dce759ce89d (focal)
10:14:37 PM: buildbot version: 9e9fc1674276da9a9f2d77b89f9d9dce759ce89d
10:14:37 PM: Fetching cached dependencies
10:14:37 PM: Starting to download cache of 329.2MB
10:14:40 PM: Finished downloading cache in 2.794s
10:14:40 PM: Starting to extract cache
10:14:42 PM: Finished extracting cache in 2.738s
10:14:42 PM: Finished fetching cache in 5.597s
10:14:42 PM: Starting to prepare the repo for build
10:14:43 PM: Preparing Git Reference refs/heads/main
10:14:44 PM: Parsing package.json dependencies
10:14:45 PM: Starting build script
10:14:45 PM: Installing dependencies
10:14:45 PM: Python version set to 2.7
10:14:45 PM: Started restoring cached Node.js version
10:14:46 PM: Finished restoring cached Node.js version
10:14:47 PM: v16.19.1 is already installed.
10:14:47 PM: Now using node v16.19.1 (npm v8.19.3)
10:14:47 PM: Enabling Node.js Corepack
10:14:47 PM: Started restoring cached build plugins
10:14:47 PM: Finished restoring cached build plugins
10:14:47 PM: Attempting Ruby version 2.7.2, read from environment
10:14:48 PM: Using Ruby version 2.7.2
10:14:48 PM: Using PHP version 8.0
10:14:48 PM: Started restoring cached corepack dependencies
10:14:48 PM: Finished restoring cached corepack dependencies
10:14:48 PM: No npm workspaces detected
10:14:48 PM: Started restoring cached node modules
10:14:48 PM: Finished restoring cached node modules
10:14:48 PM: Installing npm packages using npm version 8.19.3
10:14:49 PM: npm WARN old lockfile
10:14:49 PM: npm WARN old lockfile The package-lock.json file was created with an old version of npm,
10:14:49 PM: npm WARN old lockfile so supplemental metadata must be fetched from the registry.
10:14:49 PM: npm WARN old lockfile
10:14:49 PM: npm WARN old lockfile This is a one-time fix-up, please be patient…
10:14:49 PM: npm WARN old lockfile
10:14:59 PM: up to date, audited 389 packages in 10s
10:14:59 PM: 94 packages are looking for funding
10:14:59 PM: run npm fund for details
10:14:59 PM: 4 high severity vulnerabilities
10:14:59 PM: To address all issues, run:
10:14:59 PM: npm audit fix
10:14:59 PM: Run npm audit for details.
10:14:59 PM: npm packages installed
10:14:59 PM: Started restoring cached go cache
10:14:59 PM: Finished restoring cached go cache
10:14:59 PM: go version go1.19.7 linux/amd64
10:14:59 PM: Detected 1 framework(s)
10:14:59 PM: “next” at version “12.3.4”
10:14:59 PM: Section completed: initializing
10:15:01 PM: ​
10:15:01 PM: Netlify Build
10:15:01 PM: ────────────────────────────────────────────────────────────────
10:15:01 PM: ​
10:15:01 PM: ❯ Version
10:15:01 PM: @netlify/build 29.6.8
10:15:01 PM: ​
10:15:01 PM: ❯ Flags
10:15:01 PM: baseRelDir: true
10:15:01 PM: buildId: 6413476ae8cfde0008c1e260
10:15:01 PM: deployId: 6413476ae8cfde0008c1e262
10:15:01 PM: ​
10:15:01 PM: ❯ Current directory
10:15:01 PM: /opt/build/repo
10:15:01 PM: ​
10:15:01 PM: ❯ Config file
10:15:01 PM: No config file was defined: using default values.
10:15:01 PM: ​
10:15:01 PM: ❯ Context
10:15:01 PM: production
10:15:01 PM: ​
10:15:01 PM: ❯ Using Next.js Runtime - v4.32.2
10:15:02 PM: ​
10:15:02 PM: 1. @netlify/plugin-nextjs (onPreBuild event)
10:15:02 PM: ────────────────────────────────────────────────────────────────
10:15:02 PM: ​
10:15:02 PM: Next.js cache restored.
10:15:02 PM: Netlify configuration property “build.environment.NEXT_PRIVATE_TARGET” value changed.
10:15:02 PM: ​
10:15:02 PM: (@netlify/plugin-nextjs onPreBuild completed in 179ms)
10:15:02 PM: ​
10:15:02 PM: 2. Build command from Netlify app
10:15:02 PM: ────────────────────────────────────────────────────────────────
10:15:02 PM: ​
10:15:02 PM: $ npm run build
10:15:02 PM: > build
10:15:02 PM: > next build
10:15:03 PM: info - Linting and checking validity of types…
10:15:05 PM: ./pages/confirm.js
10:15:05 PM: 150:17 Warning: img elements must have an alt prop, either with meaningful text, or an empty string for decorative images. jsx-a11y/alt-text
10:15:05 PM: ./pages/searchresult.js
10:15:05 PM: 18:6 Warning: React Hook useEffect has a missing dependency: ‘router.isReady’. Either include it or remove the dependency array. react-hooks/exhaustive-deps
10:15:05 PM: ./pages/trainSearch.js
10:15:05 PM: 17:6 Warning: React Hook useEffect has a missing dependency: ‘router.isReady’. Either include it or remove the dependency array. react-hooks/exhaustive-deps
10:15:05 PM: info - Need to disable some ESLint rules? Learn more here: Basic Features: ESLint | Next.js
10:15:05 PM: info - Creating an optimized production build…
10:15:12 PM: warn - Compiled with warnings
10:15:12 PM: ./pages/api/flights/[id].js
10:15:12 PM: Attempted import error: ‘flights’ is not exported from ‘./data’ (imported as ‘flights’).
10:15:12 PM: ./pages/api/flights/index.js
10:15:12 PM: Attempted import error: ‘flights’ is not exported from ‘./data’ (imported as ‘flights’).
10:15:12 PM: info - Collecting page data…
10:15:14 PM: info - Generating static pages (0/14)
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: info - Generating static pages (3/14)
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: Error occurred prerendering page “/trainSearch”. Read more: prerender-error | Next.js
10:15:15 PM: TypeError: Cannot read properties of undefined (reading ‘toLowerCase’)
10:15:15 PM: at TrainSearch (/opt/build/repo/.next/server/pages/trainSearch.js:54:71)
10:15:15 PM: at d (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:33:498)
10:15:15 PM: at bb (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:36:16)
10:15:15 PM: at a.b.render (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:42:43)
10:15:15 PM: at a.b.read (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:41:83)
10:15:15 PM: at Object.exports.renderToString (/opt/build/repo/node_modules/react-dom/cjs/react-dom-server.node.production.min.js:52:138)
10:15:15 PM: at Object.renderPage (/opt/build/repo/node_modules/next/dist/server/render.js:680:46)
10:15:15 PM: at Object.defaultGetInitialProps (/opt/build/repo/node_modules/next/dist/server/render.js:350:67)
10:15:15 PM: at Function.getInitialProps (/opt/build/repo/.next/server/chunks/859.js:28:20)
10:15:15 PM: at Function.getInitialProps (/opt/build/repo/.next/server/pages/_document.js:22:90)
10:15:15 PM: info - Generating static pages (6/14)
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:15 PM: {}
10:15:15 PM: info - Generating static pages (10/14)
10:15:15 PM: AUTH_context state : { user: null, authIsReady: false }
10:15:16 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)
10:15:15 PM: info - Generating static pages (14/14)
10:15:15 PM: > Build error occurred
10:15:15 PM: Error: Export encountered errors on following paths:
10:15:15 PM: /trainSearch
10:15:15 PM: at /opt/build/repo/node_modules/next/dist/export/index.js:404:19
10:15:15 PM: at runMicrotasks ()
10:15:15 PM: at processTicksAndRejections (node:internal/process/task_queues:96:5)
10:15:15 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
10:15:15 PM: at async /opt/build/repo/node_modules/next/dist/build/index.js:1230:21
10:15:15 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
10:15:15 PM: at async /opt/build/repo/node_modules/next/dist/build/index.js:1092:17
10:15:15 PM: at async Span.traceAsyncFn (/opt/build/repo/node_modules/next/dist/trace/trace.js:79:20)
10:15:15 PM: at async Object.build [as default] (/opt/build/repo/node_modules/next/dist/build/index.js:65:29)
10:15:16 PM: ​
10:15:16 PM: “build.command” failed
10:15:16 PM: ────────────────────────────────────────────────────────────────
10:15:16 PM: ​
10:15:16 PM: Error message
10:15:16 PM: Command failed with exit code 1: npm run build (Search results for '"non-zero exit code: 1"' - Netlify Support Forums)
10:15:16 PM: ​
10:15:16 PM: Error location
10:15:16 PM: In Build command from Netlify app:
10:15:16 PM: npm run build
10:15:16 PM: ​
10:15:16 PM: Resolved config
10:15:16 PM: build:
10:15:16 PM: command: npm run build
10:15:16 PM: commandOrigin: ui
10:15:16 PM: environment:
10:15:16 PM: - NEXT_PRIVATE_TARGET
10:15:16 PM: publish: /opt/build/repo/.next
10:15:16 PM: publishOrigin: ui
10:15:16 PM: plugins:
10:15:16 PM: - inputs: {}
10:15:16 PM: origin: ui
10:15:16 PM: package: ‘@netlify/plugin-nextjs’
10:15:16 PM: Caching artifacts
10:15:16 PM: Started saving node modules
10:15:16 PM: Finished saving node modules
10:15:16 PM: Started saving build plugins
10:15:16 PM: Finished saving build plugins
10:15:16 PM: Started saving corepack cache
10:15:16 PM: Finished saving corepack cache
10:15:16 PM: Started saving pip cache
10:15:16 PM: Finished saving pip cache
10:15:16 PM: Started saving emacs cask dependencies
10:15:16 PM: Finished saving emacs cask dependencies
10:15:16 PM: Started saving maven dependencies
10:15:16 PM: Finished saving maven dependencies
10:15:16 PM: Started saving boot dependencies
10:15:16 PM: Finished saving boot dependencies
10:15:16 PM: Started saving rust rustup cache
10:15:16 PM: Finished saving rust rustup cache
10:15:16 PM: Started saving go dependencies
10:15:16 PM: Finished saving go dependencies
10:15:16 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
10:15:16 PM: Failing build: Failed to build site
10:15:16 PM: Finished processing build request in 39.687s

Hi @GokZ, thanks for the post.

Kindly visit the link below to read how to solve the quoted error message above.

Kindly fix the TypeError above since it is undefined in the TrainSearch page.

Thanks.