Deploy failed - Failed during stage 'building site': Build script returned non-zero exit code: 2

Hey Folks! I’ve been trying to deploy my project but it is giving me the following error, i’ve read so many forms but didn’t able to solve it. At first it gave me an error at build section but after trying so many ways somehow made it till deploy, but now i got struck at deploy- it is giving me Deploy did not succeed: Deploy directory 'build' does not exist can someone please help me?


5:41:45 PM: build-image version: 099264affa13d33ffbaea4ccf963ddbead423c30 (focal)
5:41:45 PM: buildbot version: 099264affa13d33ffbaea4ccf963ddbead423c30
5:41:45 PM: Fetching cached dependencies
5:41:45 PM: Failed to fetch cache, continuing with build
5:41:45 PM: Starting to prepare the repo for build
5:41:45 PM: No cached dependencies found. Cloning fresh repo
5:41:45 PM: git clone --filter=blob:none https://github.com/Yasshu55/Real-Time-chatting
5:41:45 PM: Preparing Git Reference refs/heads/main
5:41:46 PM: Parsing package.json dependencies
5:41:47 PM: Different build command detected, going to use the one specified in the Netlify configuration file: 'npm run build' versus 'CI= npm run build' in the Netlify UI
5:41:47 PM: Starting to install dependencies
5:41:49 PM: v16.19.1 is already installed.
5:41:50 PM: Now using node v16.19.1 (npm v8.19.3)
5:41:50 PM: Enabling Node.js Corepack
5:41:50 PM: Started restoring cached build plugins
5:41:50 PM: Finished restoring cached build plugins
5:41:50 PM: WARNING: The environment variable 'NODE_ENV' is set to 'production'. Any 'devDependencies' in package.json will not be installed
5:41:50 PM: Started restoring cached corepack dependencies
5:41:50 PM: Finished restoring cached corepack dependencies
5:41:50 PM: No npm workspaces detected
5:41:50 PM: Started restoring cached node modules
5:41:50 PM: Finished restoring cached node modules
5:41:50 PM: Installing npm packages using npm version 8.19.3
5:41:54 PM: npm WARN deprecated w3c-hr-time@1.0.2: Use your platform's native performance.now() and performance.timeOrigin.
npm WARN deprecated stable@0.1.8: Modern JS already guarantees Array#sort() is a stable sort, so this library is deprecated. See the compatibility table on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/sort#browser_compatibility
5:41:57 PM: npm WARN deprecated svgo@1.3.2: This SVGO version is no longer supported. Upgrade to v2.x.x.
5:42:01 PM: added 1327 packages, and audited 1328 packages in 11s
5:42:01 PM: 215 packages are looking for funding
5:42:01 PM:   run `npm fund` for details
5:42:01 PM: 10 vulnerabilities (1 moderate, 9 high)
5:42:01 PM: To address issues that do not require attention, run:
5:42:01 PM:   npm audit fix
5:42:01 PM: To address all issues (including breaking changes), run:
5:42:01 PM:   npm audit fix --force
5:42:01 PM: Run `npm audit` for details.
5:42:02 PM: npm packages installed
5:42:02 PM: Python version set to 3.8
5:42:02 PM: Using PHP version 8.0
5:42:02 PM: Attempting Ruby version 2.7.2, read from environment
5:42:03 PM: Using Ruby version 2.7.2
5:42:03 PM: Started restoring cached go cache
5:42:03 PM: Finished restoring cached go cache
5:42:03 PM: Installing Go version 1.19.5 (requested 1.19.5)
5:42:09 PM: go version go1.19.5 linux/amd64
5:42:11 PM: Install dependencies script success
5:42:11 PM: Starting build script
5:42:11 PM: Using stage install dependencies
5:42:11 PM: Detected 1 framework(s)
5:42:11 PM: "create-react-app" at version "5.0.1"
5:42:11 PM: Section completed: initializing
5:42:13 PM: ​
5:42:13 PM:   Netlify Build                                                 
5:42:13 PM: ────────────────────────────────────────────────────────────────
5:42:13 PM: ​
5:42:13 PM: ❯ Version
5:42:13 PM:   @netlify/build 29.7.1
5:42:13 PM: ​
5:42:13 PM: ❯ Flags
5:42:13 PM:   baseRelDir: true
5:42:13 PM:   buildId: 641d937ed7341f1471e7e566
5:42:13 PM:   deployId: 641d937ed7341f1471e7e568
5:42:13 PM: ​
5:42:13 PM: ❯ Current directory
5:42:13 PM:   /opt/build/repo
5:42:13 PM: ​
5:42:13 PM: ❯ Config file
5:42:13 PM:   /opt/build/repo/netlify.toml
5:42:13 PM: ​
5:42:13 PM: ❯ Context
5:42:13 PM:   production
5:42:13 PM: ​
5:42:13 PM:   1. build.command from netlify.toml                            
5:42:13 PM: ────────────────────────────────────────────────────────────────
5:42:13 PM: ​
5:42:13 PM: $ npm run build
5:42:13 PM: > userauthjwt1@1.0.0 build
5:42:13 PM: > cd client && react-scripts build
5:42:14 PM: Creating an optimized production build...
5:42:22 PM: Compiled successfully.
5:42:22 PM: 
5:42:22 PM: File sizes after gzip:
5:42:22 PM:   91.35 kB  build/static/js/main.59c07257.js
5:42:22 PM: The project was built assuming it is hosted at /.
5:42:22 PM: You can control this with the homepage field in your package.json.
5:42:22 PM: The build folder is ready to be deployed.
5:42:22 PM: You may serve it with a static server:
5:42:22 PM:   npm install -g serve
5:42:22 PM:   serve -s build
5:42:22 PM: Find out more about deployment here:
5:42:22 PM:   https://cra.link/deployment
5:42:22 PM: ​
5:42:22 PM: (build.command completed in 9.3s)
5:42:22 PM: ​
5:42:22 PM:   2. Deploy site                                                
5:42:22 PM: ────────────────────────────────────────────────────────────────
5:42:22 PM: ​
5:42:22 PM: Section completed: deploying
5:42:22 PM: ​
5:42:22 PM:   Configuration error                                           
5:42:22 PM: ────────────────────────────────────────────────────────────────
5:42:22 PM: ​
5:42:22 PM:   Error message
5:42:22 PM:   Deploy did not succeed: Deploy directory 'build' does not exist
5:42:22 PM: ​
5:42:22 PM:   Resolved config
5:42:22 PM:   build:
5:42:22 PM:     command: npm run build
5:42:23 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
5:42:22 PM:     commandOrigin: config
5:42:22 PM:     environment:
5:42:22 PM:       - CI
5:42:22 PM:       - NODE_ENV
5:42:22 PM:     publish: /opt/build/repo/build
5:42:22 PM:     publishOrigin: ui
5:42:23 PM: Caching artifacts
5:42:23 PM: Started saving node modules
5:42:23 PM: Finished saving node modules
5:42:23 PM: Started saving build plugins
5:42:23 PM: Finished saving build plugins
5:42:23 PM: Started saving corepack cache
5:42:23 PM: Finished saving corepack cache
5:42:23 PM: Started saving pip cache
5:42:23 PM: Finished saving pip cache
5:42:23 PM: Started saving emacs cask dependencies
5:42:23 PM: Finished saving emacs cask dependencies
5:42:23 PM: Started saving maven dependencies
5:42:23 PM: Finished saving maven dependencies
5:42:23 PM: Started saving boot dependencies
5:42:23 PM: Finished saving boot dependencies
5:42:23 PM: Started saving rust rustup cache
5:42:23 PM: Finished saving rust rustup cache
5:42:23 PM: Started saving go dependencies
5:42:23 PM: Finished saving go dependencies
5:42:23 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
5:42:23 PM: Failing build: Failed to build site
5:42:24 PM: Finished processing build request in 38.799s

This is my project files - GitHub - Yasshu55/Real-time-chat

As per this message, there is no build directory.

This is what is configured as the publish directory.

However, looking at the package.json in the project repository you have shared, the build is taking place in the client directory. Thus the output from react-scripts is client/build.

Rather than having the build script set to cd cient && react-scripts build better to set the base directory in the build settings to client, use npm run build for the build command (there is a package.json in the client directory) making the publish directory client/build, e.g.