Build script returned non-zero exit code: 2 for Static Webpage

Hi there my name is Kris and I am new in developing with NextJs.

I need help about my build here, I always get error which is not specific
“Build script returned non-zero exit code: 2” and said “build.command failed”. I tried to check every libraries that I had about this conflict but can’t find the way out. Please help!

  • My site: https://app.netlify.com/sites/lucky-hummingbird-9bd784/

Here is the screenshot of error

Tip: code block is better than screenshots

this is the error code block. I tried using CI or not still the same issue

4:09:25 PM: Netlify Build                                                 
4:09:25 PM: ────────────────────────────────────────────────────────────────
4:09:25 PM: ​
4:09:25 PM: ❯ Version
4:09:25 PM:   @netlify/build 29.31.1
4:09:25 PM: ​
4:09:25 PM: ❯ Flags
4:09:25 PM:   baseRelDir: true
4:09:25 PM:   buildId: 6584631fbd2a3812dcdf114e
4:09:25 PM:   deployId: 6584631fbd2a3812dcdf1150
4:09:25 PM: ​
4:09:25 PM: ❯ Current directory
4:09:25 PM:   /opt/build/repo
4:09:25 PM: ​
4:09:25 PM: ❯ Config file
4:09:25 PM:   No config file was defined: using default values.
4:09:25 PM: ​
4:09:25 PM: ❯ Context
4:09:25 PM:   production
4:09:25 PM: ​
4:09:25 PM: ❯ Installing plugins
4:09:25 PM:    - @netlify/plugin-lighthouse@5.0.0
4:09:35 PM: ​
4:09:35 PM: ❯ Loading plugins
4:09:35 PM:    - @netlify/plugin-lighthouse@5.0.0 from Netlify app
4:09:37 PM: ​
4:09:37 PM: Build command from Netlify app                                
4:09:37 PM: ────────────────────────────────────────────────────────────────
4:09:37 PM: ​
4:09:37 PM: $ CI= npm run build
4:09:37 PM: > helo-website-project@0.1.0 build
4:09:37 PM: > next build && next export
4:09:37 PM: ⚠ No build cache found. Please configure build caching for faster rebuilds. Read more: https://nextjs.org/docs/messages/no-cache
4:09:37 PM:    Linting and checking validity of types ...
4:09:41 PM:    ▲ Next.js 14.0.4
4:09:41 PM:    Creating an optimized production build ...
4:09:48 PM:  ✓ Compiled successfully
4:09:48 PM:    Collecting page data ...
4:09:49 PM:    Generating static pages (0/8) ...
4:09:49 PM:    Generating static pages (2/8)
4:09:49 PM:    Generating static pages (4/8)
4:09:49 PM:    Generating static pages (6/8)
4:09:50 PM: An aria-label or aria-labelledby prop is required for accessibility.
4:09:50 PM:  ✓ Generating static pages (8/8)
4:09:51 PM:    Finalizing page optimization ...
4:09:51 PM:    Collecting build traces ...
4:10:00 PM: Route (pages)                              Size     First Load JS
4:10:00 PM: ┌ ○ /                                      3.68 kB        91.2 kB
4:10:00 PM: ├   └ css/92da734fc2a09bcb.css             3.52 kB
4:10:00 PM: ├   /_app                                  0 B            79.3 kB
4:10:00 PM: ├ ○ /404                                   181 B          79.4 kB
4:10:00 PM: ├ ○ /about_us                              3.75 kB        91.3 kB
4:10:00 PM: ├   ├ css/ce6c77c907964807.css             6.56 kB
4:10:00 PM: ├   └ css/3beb031e03907d1b.css             2.74 kB
4:10:00 PM: ├ ○ /cookies                               3.99 kB        91.5 kB
4:10:00 PM: ├   └ css/eb27d07bf25e951b.css             2.34 kB
4:10:00 PM: ├ ○ /find_jobs (338 ms)                    28.1 kB         116 kB
4:10:00 PM: ├   └ css/35cdd59379406e1e.css             3.71 kB
4:10:00 PM: ├ ○ /policy (867 ms)                       63.2 kB         151 kB
4:10:00 PM: ├   └ css/34766f2a22315c12.css             2.68 kB
4:10:00 PM: └ ○ /services                              4.01 kB        91.5 kB
4:10:00 PM:     └ css/b3b93b6e17840a91.css             2.47 kB
4:10:00 PM: + First Load JS shared by all              110 kB
4:10:00 PM:   ├ chunks/framework-5429a50ba5373c56.js   45.2 kB
4:10:00 PM:   ├ chunks/main-0faf54d7be07776a.js        31.7 kB
4:10:00 PM:   ├ chunks/pages/_app-b6e96b6b1eb7abad.js  442 B
4:10:00 PM:   ├ chunks/webpack-d1bff2d148f4639a.js     1.96 kB
4:10:00 PM:   └ css/315c0d3e2f07dfe5.css               30.8 kB
4:10:00 PM: ○  (Static)  prerendered as static content
4:10:00 PM:  ⨯
4:10:00 PM:     The "next export" command has been removed in favor of "output: export" in next.config.js. Learn more: https://nextjs.org/docs/advanced-features/static-html-export
4:10:00 PM: ​
4:10:00 PM: "build.command" failed                                        
4:10:00 PM: ────────────────────────────────────────────────────────────────
4:10:00 PM: ​
4:10:00 PM:   Error message
4:10:00 PM:   Command failed with exit code 1: CI= npm run build (https://ntl.fyi/exit-code-1)
4:10:00 PM: ​
4:10:00 PM:   Error location
4:10:00 PM:   In Build command from Netlify app:
4:10:00 PM:   CI= npm run build
4:10:00 PM: ​
4:10:00 PM:   Resolved config
4:10:00 PM:   build:
4:10:00 PM:     base: /opt/build/repo
4:10:00 PM:     command: CI= npm run build
4:10:00 PM:     commandOrigin: ui
4:10:00 PM:     publish: /opt/build/repo
4:10:00 PM:     publishOrigin: default
4:10:00 PM:   plugins:
4:10:00 PM:     - inputs: {}
4:10:00 PM:       origin: ui
4:10:00 PM:       package: "@netlify/plugin-lighthouse"
4:10:01 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
4:10:01 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
4:10:01 PM: Failing build: Failed to build site
4:10:01 PM: Finished processing build request in 56.561s

Have you checked these lines?

Yes, but not helpful

I have successfully repack it again, but then when I tried to change some codes regarding my code logic, then it happened again here:

4:06:29 PM: Netlify Build                                                 
4:06:29 PM: ────────────────────────────────────────────────────────────────
4:06:29 PM: ​
4:06:29 PM: ❯ Version
4:06:29 PM:   @netlify/build 29.31.1
4:06:29 PM: ​
4:06:29 PM: ❯ Flags
4:06:29 PM:   baseRelDir: true
4:06:29 PM:   buildId: 658c4b7163ca8c00082fce3e
4:06:29 PM:   deployId: 658c4b7163ca8c00082fce40
4:06:29 PM: ​
4:06:29 PM: ❯ Current directory
4:06:29 PM:   /opt/build/repo
4:06:29 PM: ​
4:06:29 PM: ❯ Config file
4:06:29 PM:   No config file was defined: using default values.
4:06:29 PM: ​
4:06:29 PM: ❯ Context
4:06:29 PM:   production
4:06:29 PM: ​
4:06:29 PM: ❯ Using Next.js Runtime - v4.41.3
4:06:29 PM: ​
4:06:29 PM: ❯ Loading plugins
4:06:29 PM:    - @netlify/plugin-lighthouse@5.0.0 from Netlify app
4:06:31 PM: ​
4:06:31 PM: @netlify/plugin-nextjs (onPreBuild event)                     
4:06:31 PM: ────────────────────────────────────────────────────────────────
4:06:31 PM: ​
4:06:31 PM: Next.js cache restored.
4:06:31 PM: Not running Next Runtime
4:06:31 PM: ​
4:06:31 PM: (@netlify/plugin-nextjs onPreBuild completed in 92ms)
4:06:31 PM: ​
4:06:31 PM: Build command from Netlify app                                
4:06:31 PM: ────────────────────────────────────────────────────────────────
4:06:31 PM: ​
4:06:31 PM: $ npm run build
4:06:31 PM: > helo-website@0.1.0 build
4:06:31 PM: > next build
4:06:32 PM:    Linting and checking validity of types ...
4:06:34 PM:    ▲ Next.js 14.0.4
4:06:34 PM:    Creating an optimized production build ...
4:06:35 PM: warn - The glob pattern ./src/**/*.{js.ts.tsx.jsx} in your Tailwind CSS configuration is invalid.
4:06:35 PM: warn - Update it to ./src/**/*.js.ts.tsx.jsx to silence this warning.
4:06:35 PM: 🌼   daisyUI 4.4.23
4:06:35 PM: ├─ ✔︎ 2 themes added		https://daisyui.com/docs/themes
4:06:35 PM: ╰─ ★ Star daisyUI on GitHub	https://github.com/saadeghi/daisyui
4:06:37 PM: 🌼   daisyUI 4.4.23
4:06:37 PM: ├─ ✔︎ 2 themes added		https://daisyui.com/docs/themes
4:06:37 PM: ╰─ ★ Star daisyUI on GitHub	https://github.com/saadeghi/daisyui
4:06:37 PM: warn - No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.
4:06:37 PM: warn - https://tailwindcss.com/docs/content-configuration
4:06:39 PM:  ✓ Compiled successfully
4:06:39 PM:    Collecting page data ...
4:06:41 PM:    Generating static pages (0/9) ...
4:06:41 PM:    Generating static pages (2/9)
4:06:41 PM:    Generating static pages (4/9)
4:06:41 PM: Error occurred prerendering page "/find_jobs". Read more: https://nextjs.org/docs/messages/prerender-error
4:06:41 PM: TypeError: fetch failed
4:06:41 PM:     at Object.fetch (node:internal/deps/undici/undici:11730:11)
4:06:41 PM:     at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
4:06:41 PM:     at async j (/opt/build/repo/.next/server/pages/find_jobs.js:1:36349)
4:06:41 PM:    Generating static pages (6/9)
4:06:42 PM: An aria-label or aria-labelledby prop is required for accessibility.
4:06:42 PM:  ✓ Generating static pages (9/9)
4:06:42 PM: > Export encountered errors on following paths:
4:06:42 PM: 	/find_jobs
4:06:42 PM: ​
4:06:42 PM: "build.command" failed                                        
4:06:42 PM: ────────────────────────────────────────────────────────────────
4:06:42 PM: ​
4:06:42 PM:   Error message
4:06:42 PM:   Command failed with exit code 1: npm run build (https://ntl.fyi/exit-code-1)
4:06:42 PM: ​
4:06:42 PM:   Error location
4:06:42 PM:   In Build command from Netlify app:
4:06:42 PM:   npm run build
4:06:42 PM: ​
4:06:42 PM:   Resolved config
4:06:42 PM:   build:
4:06:42 PM:     command: npm run build
4:06:42 PM:     commandOrigin: ui
4:06:42 PM:     environment:
4:06:42 PM:       - NETLIFY_NEXT_PLUGIN_SKIP
4:06:42 PM:     publish: /opt/build/repo/out
4:06:42 PM:     publishOrigin: ui
4:06:42 PM:   plugins:
4:06:42 PM:     - inputs: {}
4:06:42 PM:       origin: ui
4:06:42 PM:       package: "@netlify/plugin-nextjs"
4:06:42 PM:     - inputs: {}
4:06:42 PM:       origin: ui
4:06:42 PM:       package: "@netlify/plugin-lighthouse"
4:06:42 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
4:06:43 PM: Failed during stage "building site": Build script returned non-zero exit code: 2
4:06:43 PM: Failing build: Failed to build site
4:06:43 PM: Finished processing build request in 32.79s

Hi, @kris-mhc. Yes, there is a new error in your build logs here:

The solution here will be to find the cause of that error and resolve it to get the build to succeed. Our support team cannot see your code or access your repo. Because of this, we cannot tell you what reason is for this error.

If there are other questions about this, please let us know.