# Build problem: Failed but Published, "Build script returned non-zero exit code: 2"

**URL:** <https://answers.netlify.com/t/build-problem-failed-but-published-build-script-returned-non-zero-exit-code-2/110224>\
**Category:** Support\
**Tags:** building, deployment\
**Created:** [January 12, 2024, 3:50am UTC](https://answers.netlify.com/t/build-problem-failed-but-published-build-script-returned-non-zero-exit-code-2/110224 "2024-01-12T03:50:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![yiaya001](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/yiaya001/32/57877_2.png) [@yiaya001](https://answers.netlify.com/u/yiaya001)\
**Post date:** [January 12, 2024, 3:50am UTC](https://answers.netlify.com/t/build-problem-failed-but-published-build-script-returned-non-zero-exit-code-2/110224/1 "2024-01-12T03:50:54Z")

</div>

My netlify site name: [yiaya.netlify.app](https://yiaya.netlify.app)  
It’s forked from [https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web)

I got a wierd problem while deploy, it failed while building , but completed the other steps.  
It shows “Published” but "Failed during stage ‘building site’:Build script returned non-zero exit code: 2“

Here is deploy log:

8:27:59 AM: Build ready to start  
8:28:00 AM: build-image version: 2821c5fd78f4042b4bb03d028b1983667d2e2d9c (focal)  
8:28:00 AM: buildbot version: 9c122e4d38ef873d49667acc314f41647c44b72a  
8:28:01 AM: Fetching cached dependencies  
8:28:01 AM: Failed to fetch cache, continuing with build  
8:28:01 AM: Starting to prepare the repo for build  
8:28:01 AM: No cached dependencies found. Cloning fresh repo  
8:28:01 AM: git clone --filter=blob:none [GitHub - ChatGPTNextWeb/ChatGPT-Next-Web: A cross-platform ChatGPT/Gemini UI (Web / PWA / Linux / Win / MacOS). 一键拥有你自己的跨平台 ChatGPT/Gemini 应用。](https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web)  
8:28:01 AM: Preparing Git Reference refs/heads/main  
8:28:03 AM: Starting to install dependencies  
8:28:03 AM: Python version set to 3.8  
8:28:03 AM: Attempting Ruby version 2.7.2, read from environment  
8:28:03 AM: Using Ruby version 2.7.2  
8:28:04 AM: Started restoring cached go cache  
8:28:04 AM: Finished restoring cached go cache  
8:28:04 AM: go version go1.19.13 linux/amd64  
8:28:04 AM: Using PHP version 8.0  
8:28:05 AM: v18.19.0 is already installed.  
8:28:05 AM: Now using node v18.19.0 (npm v10.2.3)  
8:28:05 AM: Enabling Node.js Corepack  
8:28:06 AM: Started restoring cached build plugins  
8:28:06 AM: Finished restoring cached build plugins  
8:28:06 AM: Started restoring cached corepack dependencies  
8:28:06 AM: Finished restoring cached corepack dependencies  
8:28:06 AM: Started restoring cached yarn cache  
8:28:06 AM: Finished restoring cached yarn cache  
8:28:06 AM: No yarn workspaces detected  
8:28:06 AM: Started restoring cached node modules  
8:28:06 AM: Finished restoring cached node modules  
8:28:06 AM: Installing npm packages using Yarn version 1.22.19  
8:28:07 AM: yarn install v1.22.19  
8:28:07 AM: [1/4] Resolving packages…  
8:28:07 AM: [2/4] Fetching packages…  
8:28:29 AM: [3/4] Linking dependencies…  
8:28:34 AM: [4/4] Building fresh packages…  
8:28:34 AM: $ husky install  
8:28:34 AM: husky - Git hooks installed  
8:28:34 AM: Done in 27.49s.  
8:28:34 AM: npm packages installed using Yarn  
8:28:35 AM: Successfully installed dependencies  
8:28:35 AM: Starting build script  
8:28:35 AM: Detected 1 framework(s)  
8:28:35 AM: “next” at version “13.4.9”  
8:28:35 AM: Section completed: initializing  
8:28:37 AM: ​  
8:28:37 AM: Netlify Build  
8:28:37 AM: ────────────────────────────────────────────────────────────────  
8:28:37 AM: ​  
8:28:37 AM: ❯ Version  
8:28:37 AM: @netlify/build 29.31.4  
8:28:37 AM: ​  
8:28:37 AM: ❯ Flags  
8:28:37 AM: baseRelDir: true  
8:28:37 AM: buildId: 659f360f6550090008cf9bc5  
8:28:37 AM: deployId: 659f360f6550090008cf9bc7  
8:28:37 AM: ​  
8:28:37 AM: ❯ Current directory  
8:28:37 AM: /opt/build/repo  
8:28:37 AM: ​  
8:28:37 AM: ❯ Config file  
8:28:37 AM: No config file was defined: using default values.  
8:28:37 AM: ​  
8:28:37 AM: ❯ Context  
8:28:37 AM: production  
8:28:37 AM: ​  
8:28:37 AM: ❯ Installing plugins  
8:28:37 AM: - @netlify/plugin-nextjs@4.41.3  
8:28:50 AM: ​  
8:28:50 AM: ❯ Using Next.js Runtime - v4.41.3  
8:28:51 AM: ​  
8:28:51 AM: @netlify/plugin-nextjs (onPreBuild event)  
8:28:51 AM: ────────────────────────────────────────────────────────────────  
8:28:51 AM: ​  
8:28:51 AM: No Next.js cache to restore.  
8:28:51 AM: Netlify configuration property “build.environment.NEXT\_PRIVATE\_TARGET” value changed.  
8:28:51 AM: ​  
8:28:51 AM: (@netlify/plugin-nextjs onPreBuild completed in 51ms)  
8:28:51 AM: ​  
8:28:51 AM: Build command from Netlify app  
8:28:51 AM: ────────────────────────────────────────────────────────────────  
8:28:51 AM: ​  
8:28:51 AM: $ CI= yarn build  
8:28:51 AM: yarn run v1.22.19  
8:28:51 AM: $ cross-env BUILD\_MODE=standalone next build  
8:28:51 AM: [Next] build mode standalone  
8:28:51 AM: [Next] build with chunk: true  
8:28:51 AM: - warn You have enabled experimental feature (forceSwcTransforms) in next.config.mjs.  
8:28:51 AM: - warn Experimental features are not covered by semver, and may cause unexpected or broken application behavior. Use at your own risk.  
8:28:51 AM: - warn No build cache found. Please configure build caching for faster rebuilds. Read more: https:/nextjs.org/docs/messages/no-cache  
8:28:51 AM: - info Creating an optimized production build…  
8:28:53 AM: Browserslist: caniuse-lite is outdated. Please run:  
8:28:53 AM: npx browserslist@latest --update-db  
8:28:53 AM: Why you should do it regularly: https:/github.com/browserslist/browserslist#browsers-data-updating  
8:28:54 AM: Warning: For production Image Optimization with Next.js, the optional “sharp” package is strongly recommended. Run “yarn add sharp”, and Next.js will use it automatically for Image Optimization.  
8:28:54 AM: Read more: https:/nextjs.org/docs/messages/sharp-missing-in-production  
8:29:25 AM: - info Compiled successfully  
8:29:25 AM: - info Linting and checking validity of types…  
8:29:30 AM: - info Collecting page data…  
8:29:30 AM: [Server Config] using 1 of 1 api key  
8:29:30 AM: [Server Config] using 1 of 1 api key  
8:29:30 AM: [Server Config] using 1 of 1 api key  
8:29:31 AM: [Server Config] using 1 of 1 api key  
8:29:44 AM: - info Generating static pages (0/3)  
8:29:44 AM: [Server Config] using 1 of 1 api key  
8:29:44 AM: [Server Config] using 1 of 1 api key  
8:29:44 AM: - info Generating static pages (3/3)  
8:29:45 AM: - info Finalizing page optimization…  
8:29:45 AM: Route (app) Size First Load JS  
8:29:45 AM: ┌ ○ / 102 kB 181 kB  
8:29:45 AM: ├ ℇ /api/config 0 B 0 B  
8:29:45 AM: ├ λ /api/cors/[…path] 0 B 0 B  
8:29:45 AM: ├ ℇ /api/google/[…path] 0 B 0 B  
8:29:45 AM: └ ℇ /api/openai/[…path] 0 B 0 B  
8:29:45 AM: + First Load JS shared by all 79.1 kB  
8:29:45 AM: ├ chunks/7698-a48a6760e2d976ac.js 25.3 kB  
8:29:45 AM: ├ chunks/bce60fc1-d9747a6859a4a025.js 50.6 kB  
8:29:45 AM: ├ chunks/main-app-906be45bc0beecce.js 223 B  
8:29:45 AM: └ chunks/webpack-43c5c88786838c6e.js 3.06 kB  
8:29:45 AM: Route (pages) Size First Load JS  
8:29:45 AM: ─ ○ /404 184 B 81 kB  
8:29:45 AM: + First Load JS shared by all 80.8 kB  
8:29:45 AM: ├ chunks/framework-4498e84bb0ba1830.js 45.1 kB  
8:29:45 AM: ├ chunks/main-69c6a49da1f94a59.js 32.5 kB  
8:29:45 AM: ├ chunks/pages/\_app-0fe44225c17aa1f2.js 198 B  
8:29:45 AM: └ chunks/webpack-43c5c88786838c6e.js 3.06 kB  
8:29:45 AM: ℇ (Streaming) server-side renders with streaming (uses React 18 SSR streaming or Server Components)  
8:29:45 AM: λ (Server) server-side renders at runtime (uses getInitialProps or getServerSideProps)  
8:29:45 AM: ○ (Static) automatically rendered as static HTML (uses no initial props)  
8:29:45 AM: Done in 54.63s.  
8:29:45 AM: ​  
8:29:45 AM: (build.command completed in 54.8s)  
8:29:45 AM: ​  
8:29:45 AM: @netlify/plugin-nextjs (onBuild event)  
8:29:45 AM: ────────────────────────────────────────────────────────────────  
8:29:45 AM: ​  
8:29:46 AM: Moving static page files to serve from CDN…  
8:29:46 AM: Moved 4 files to CDN  
8:29:46 AM: You are not using Netlify Edge Functions for image format detection. Set env var “NEXT\_FORCE\_EDGE\_IMAGES=true” to enable.  
8:29:46 AM: ✨ Deploying middleware and functions to Netlify Edge Functions ✨  
8:29:46 AM: Netlify configuration property “redirects” value changed to [  
8:29:46 AM: { from: “/_next/static/", to: “/static/:splat”, status: 200 },  
8:29:46 AM: {  
8:29:46 AM: from: "/\_next/image",  
8:29:46 AM: query: { url: “:url”, w: “:width”, q: “:quality” },  
8:29:46 AM: to: "/ipx/w:width,q_:quality/:url”,  
8:29:46 AM: status: 301  
8:29:46 AM: },  
8:29:46 AM: { from: “/\_ipx/_", to: “/.netlify/builders/\_ipx”, status: 200 },  
8:29:46 AM: {  
8:29:46 AM: from: "/api/_”,  
8:29:46 AM: to: “/.netlify/functions/\_\_\_netlify-handler”,  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/android-chrome-192x192.png”,  
8:29:46 AM: to: “/android-chrome-192x192.png”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/android-chrome-512x512.png”,  
8:29:46 AM: to: “/android-chrome-512x512.png”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/apple-touch-icon.png”,  
8:29:46 AM: to: “/apple-touch-icon.png”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/favicon-16x16.png”,  
8:29:46 AM: to: “/favicon-16x16.png”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/favicon-32x32.png”,  
8:29:46 AM: to: “/favicon-32x32.png”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/favicon.ico”,  
8:29:46 AM: to: “/favicon.ico”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/macos.png”,  
8:29:46 AM: to: “/macos.png”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/prompts.json”,  
8:29:46 AM: to: “/prompts.json”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/robots.txt”,  
8:29:46 AM: to: “/robots.txt”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/serviceWorker.js”,  
8:29:46 AM: to: “/serviceWorker.js”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/serviceWorkerRegister.js”,  
8:29:46 AM: to: “/serviceWorkerRegister.js”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/site.webmanifest”,  
8:29:46 AM: to: “/site.webmanifest”,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: status: 200  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: “/_",  
8:29:46 AM: to: “/.netlify/functions/\_\_\_netlify-handler”,  
8:29:46 AM: status: 200,  
8:29:46 AM: conditions: { Cookie: [Array] },  
8:29:46 AM: force: true  
8:29:46 AM: },  
8:29:46 AM: {  
8:29:46 AM: from: "/_”,  
8:29:46 AM: to: “/.netlify/functions/\_\_\_netlify-handler”,  
8:29:46 AM: status: 200  
8:29:46 AM: }  
8:29:46 AM: ].  
8:29:46 AM: ​  
8:29:46 AM: (@netlify/plugin-nextjs onBuild completed in 180ms)  
8:29:46 AM: ​  
8:29:46 AM: Functions bundling  
8:29:46 AM: ────────────────────────────────────────────────────────────────  
8:29:46 AM: ​  
8:29:46 AM: Packaging Functions from .netlify/functions-internal directory:  
8:29:46 AM: - \_\_\_netlify-handler/\_\_\_netlify-handler.js  
8:29:46 AM: - \_\_\_netlify-odb-handler/\_\_\_netlify-odb-handler.js  
8:29:46 AM: - \_ipx/\_ipx.js  
8:29:46 AM: ​  
8:30:46 AM: ​  
8:30:46 AM: (Functions bundling completed in 1m 0.1s)  
8:30:46 AM: ​  
8:30:46 AM: Edge Functions bundling  
8:30:46 AM: ────────────────────────────────────────────────────────────────  
8:30:46 AM: ​  
8:30:46 AM: Packaging Edge Functions from .netlify/edge-functions directory:  
8:30:46 AM: - next\_app\_api\_config\_route  
8:30:46 AM: - next\_app\_api\_google\_\_\_\_\_path\_\_route  
8:30:46 AM: - next\_app\_api\_openai\_\_\_\_\_path\_\_route  
8:30:46 AM: - rsc-data  
8:30:49 AM: ​  
8:30:49 AM: (Edge Functions bundling completed in 3.6s)  
8:30:49 AM: ​  
8:30:49 AM: @netlify/plugin-nextjs (onPostBuild event)  
8:30:49 AM: ────────────────────────────────────────────────────────────────  
8:30:49 AM: ​  
8:30:50 AM: Next.js cache saved.  
8:30:50 AM: 🧪 Thank you for testing “appDir” support on Netlify. For known issues and to give feedback, visit https:/ntl.fyi/next-13-feedback  
8:30:50 AM: Netlify configuration property “headers” value changed to [  
8:30:50 AM: {  
8:30:50 AM: for: “/api/_",  
8:30:50 AM: values: {  
8:30:50 AM: “Access-Control-Allow-Credentials”: “true”,  
8:30:50 AM: “Access-Control-Allow-Origin”: "_”,  
8:30:50 AM: “Access-Control-Allow-Methods”: “_",  
8:30:50 AM: “Access-Control-Allow-Headers”: "_”,  
8:30:50 AM: “Access-Control-Max-Age”: “86400”  
8:30:50 AM: }  
8:30:50 AM: }  
8:30:50 AM: ].  
8:30:50 AM: ​  
8:30:50 AM: (@netlify/plugin-nextjs onPostBuild completed in 150ms)  
8:30:50 AM: ​  
8:30:50 AM: Deploy site  
8:30:50 AM: ────────────────────────────────────────────────────────────────  
8:30:50 AM: ​  
8:30:50 AM: Starting to deploy site from “.next”  
8:30:50 AM: Calculating files to upload  
8:30:52 AM: 6 new files to upload  
8:30:52 AM: 3 new functions to upload  
8:31:02 AM: Starting post processing  
8:31:02 AM: Skipping form detection  
8:31:02 AM: Post processing - redirect rules  
8:31:02 AM: Post processing done  
8:31:02 AM: Section completed: postprocessing  
8:31:02 AM: Post processing - header rules  
8:31:02 AM: Section completed: deploying  
8:31:02 AM: Site deploy was successfully initiated  
8:31:02 AM: ​  
8:31:02 AM: (Deploy site completed in 12.6s)  
8:31:02 AM: ​  
8:31:02 AM: Netlify Build Complete  
8:31:02 AM: ────────────────────────────────────────────────────────────────  
8:31:02 AM: ​  
8:31:02 AM: (Netlify Build completed in 2m 25.6s)  
8:31:03 AM: Site is live ✨  
8:31:03 AM: Failed during stage “building site”: Build script returned non-zero exit code: 2  
8:31:03 AM: /opt/build-bin/build: line 142: [: zl: integer expression expected  
8:31:03 AM: /opt/build-bin/build: line 148: exit: zl: numeric argument required  
8:31:03 AM: Build failed due to a user error: Build script returned non-zero exit code: 2  
8:31:03 AM: Failing build: Failed to build site  
8:31:03 AM: Finished processing build request in 3m2.539s

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [January 13, 2024, 7:53pm UTC](https://answers.netlify.com/t/build-problem-failed-but-published-build-script-returned-non-zero-exit-code-2/110224/2 "2024-01-13T19:53:59Z")

</div>

Your recent deploys seem successful. Are you still having issues?

---

<div class="post-metadata">

**Author:** ![yiaya001](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/yiaya001/32/57877_2.png) [@yiaya001](https://answers.netlify.com/u/yiaya001)\
**Post date:** [January 21, 2024, 1:14am UTC](https://answers.netlify.com/t/build-problem-failed-but-published-build-script-returned-non-zero-exit-code-2/110224/3 "2024-01-21T01:14:10Z")

</div>

Yes,I still got this message "Failed during stage ‘building site’:Build script returned non-zero exit code: 2” while pubilshed.

 ![Screenshot_2024-01-21-09-12-39-26_40deb401b9ffe8e1df2f1cc5ba480b12](https://global.discourse-cdn.com/netlify/original/3X/5/3/534f7ae30d3157fe8fc0c6d903a0bbcf98c85abc.jpeg)

---

<div class="post-metadata">

**Author:** ![hrishikesh](https://sea1.discourse-cdn.com/netlify/user_avatar/answers.netlify.com/hrishikesh/32/74607_2.png) [@hrishikesh](https://answers.netlify.com/u/hrishikesh)\
**Post date:** [January 21, 2024, 4:22pm UTC](https://answers.netlify.com/t/build-problem-failed-but-published-build-script-returned-non-zero-exit-code-2/110224/4 "2024-01-21T16:22:50Z")

</div>

But where’s this issue, I see all successful deploys:

 ![image](https://global.discourse-cdn.com/netlify/original/3X/7/0/70ec8dcc7dcc35ecea1fa3f38f41b871c73f78ed.png)
