1:52:06 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2

Site name: velvety-treacle-45c58f.netlify.app`

Log:

1:51:49 PM: build-image version: 4b067841aaa59ef71931d3505b98c2bc3e63f36f (focal)
1:51:49 PM: buildbot version: a97756545adbd82de83b06c902122c919d70e7f2
1:51:49 PM: Building without cache
1:51:49 PM: Starting to prepare the repo for build
1:51:49 PM: No cached dependencies found. Cloning fresh repo
1:51:49 PM: git clone --filter=blob:none GitHub - Glejx-code/adopt-me: The project created by Brian Holt for the "Complete Intro to React, v8" course on frontendmasters.com. The project primarily consists of ReactJS, comprising approximately 99% of the codebase.
1:51:49 PM: Preparing Git Reference refs/heads/main
1:51:51 PM: Starting to install dependencies
1:51:51 PM: Python version set to 3.8
1:51:51 PM: Attempting Ruby version 2.7.2, read from environment
1:51:52 PM: Using Ruby version 2.7.2
1:51:52 PM: Started restoring cached go cache
1:51:52 PM: Finished restoring cached go cache
1:51:54 PM: go version go1.19.9 linux/amd64
1:51:54 PM: Using PHP version 8.0
1:51:55 PM: v16.20.0 is already installed.
1:51:56 PM: Now using node v16.20.0 (npm v8.19.4)
1:51:56 PM: Enabling Node.js Corepack
1:51:56 PM: Started restoring cached build plugins
1:51:56 PM: Finished restoring cached build plugins
1:51:56 PM: Started restoring cached corepack dependencies
1:51:56 PM: Finished restoring cached corepack dependencies
1:51:56 PM: No npm workspaces detected
1:51:56 PM: Started restoring cached node modules
1:51:56 PM: Finished restoring cached node modules
1:51:56 PM: Installing npm packages using npm version 8.19.4
1:51:58 PM: npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
1:51:59 PM: added 288 packages, and audited 289 packages in 3s
1:51:59 PM: 93 packages are looking for funding
1:51:59 PM: run npm fund for details
1:51:59 PM: found 0 vulnerabilities
1:51:59 PM: npm packages installed
1:52:00 PM: Install dependencies script success
1:52:00 PM: Starting build script
1:52:01 PM: Detected 1 framework(s)
1:52:01 PM: β€œvite” at version β€œ3.1.4”
1:52:01 PM: Section completed: initializing
1:52:02 PM: ​
1:52:02 PM: Netlify Build
1:52:02 PM: ────────────────────────────────────────────────────────────────
1:52:02 PM: ​
1:52:02 PM: ❯ Version
1:52:02 PM: @netlify/build 29.11.6
1:52:02 PM: ​
1:52:02 PM: ❯ Flags
1:52:02 PM: baseRelDir: true
1:52:02 PM: buildId: 647491d1ce747377283ac7c8
1:52:02 PM: deployId: 647491d1ce747377283ac7ca
1:52:02 PM: ​
1:52:02 PM: ❯ Current directory
1:52:02 PM: /opt/build/repo
1:52:02 PM: ​
1:52:02 PM: ❯ Config file
1:52:02 PM: No config file was defined: using default values.
1:52:02 PM: ​
1:52:02 PM: ❯ Context
1:52:02 PM: production
1:52:02 PM: ​
1:52:02 PM: Build command from Netlify app
1:52:02 PM: ────────────────────────────────────────────────────────────────
1:52:02 PM: ​
1:52:02 PM: $ CI= npm run build
1:52:02 PM: > citr-v8-project@8.0.0 build
1:52:02 PM: > vite build
1:52:02 PM: vite v3.1.4 building for production…
1:52:03 PM: transforming…
1:52:04 PM: βœ“ 88 modules transformed.
1:52:04 PM: rendering chunks…
1:52:04 PM: dist/index.html 0.44 KiB
1:52:04 PM: dist/assets/index.0f0f1391.css 4.12 KiB / gzip: 1.38 KiB
1:52:04 PM: dist/assets/index.a7316fdc.js 195.28 KiB / gzip: 61.90 KiB
1:52:04 PM: ​
1:52:04 PM: (build.command completed in 2.3s)
1:52:04 PM: ​
1:52:04 PM: Deploy site
1:52:04 PM: ────────────────────────────────────────────────────────────────
1:52:04 PM: ​
1:52:04 PM: Section completed: deploying
1:52:04 PM: ​
1:52:04 PM: Configuration error
1:52:04 PM: ────────────────────────────────────────────────────────────────
1:52:04 PM: ​
1:52:04 PM: Error message
1:52:04 PM: Deploy did not succeed: Deploy directory β€˜build’ does not exist
1:52:04 PM: ​
1:52:04 PM: Resolved config
1:52:04 PM: build:
1:52:04 PM: command: CI= npm run build
1:52:04 PM: commandOrigin: ui
1:52:04 PM: environment:
1:52:04 PM: - CI
1:52:04 PM: publish: /opt/build/repo/build
1:52:04 PM: publishOrigin: ui
1:52:05 PM: Caching artifacts
1:52:05 PM: Started saving node modules
1:52:05 PM: Finished saving node modules
1:52:05 PM: Started saving build plugins
1:52:05 PM: Finished saving build plugins
1:52:05 PM: Started saving corepack cache
1:52:05 PM: Finished saving corepack cache
1:52:05 PM: Started saving pip cache
1:52:05 PM: Finished saving pip cache
1:52:05 PM: Started saving emacs cask dependencies
1:52:05 PM: Finished saving emacs cask dependencies
1:52:05 PM: Started saving maven dependencies
1:52:05 PM: Finished saving maven dependencies
1:52:05 PM: Started saving boot dependencies
1:52:06 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)
1:52:05 PM: Finished saving boot dependencies
1:52:05 PM: Started saving rust rustup cache
1:52:05 PM: Finished saving rust rustup cache
1:52:05 PM: Started saving go dependencies
1:52:05 PM: Finished saving go dependencies
1:52:06 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
1:52:06 PM: Failing build: Failed to build site
1:52:06 PM: Finished processing build request in 17.361s

This is the reason for the build failure

The reason for the above message is evident below

Vite is building to the dist directory and you are telling Netlify to deploy build.

1 Like

6:21:01 PM: build-image version: 4b067841aaa59ef71931d3505b98c2bc3e63f36f (focal)
6:21:01 PM: buildbot version: 930b741712d190756111afe3e43190c717b93e3e
6:21:01 PM: Building without cache
6:21:01 PM: Starting to prepare the repo for build
6:21:01 PM: No cached dependencies found. Cloning fresh repo
6:21:01 PM: git clone --filter=blob:none GitHub - Glejx-code/adopt-me: The project created by Brian Holt for the "Complete Intro to React, v8" course on frontendmasters.com. The project primarily consists of ReactJS, comprising approximately 99% of the codebase.
6:21:02 PM: Preparing Git Reference refs/heads/main
6:21:03 PM: Starting to install dependencies
6:21:03 PM: Python version set to 3.8
6:21:03 PM: Attempting Ruby version 2.7.2, read from environment
6:21:04 PM: Using Ruby version 2.7.2
6:21:04 PM: Started restoring cached go cache
6:21:04 PM: Finished restoring cached go cache
6:21:06 PM: go version go1.19.9 linux/amd64
6:21:06 PM: Using PHP version 8.0
6:21:07 PM: v16.20.0 is already installed.
6:21:07 PM: Now using node v16.20.0 (npm v8.19.4)
6:21:07 PM: Enabling Node.js Corepack
6:21:08 PM: Started restoring cached build plugins
6:21:08 PM: Finished restoring cached build plugins
6:21:08 PM: Started restoring cached corepack dependencies
6:21:08 PM: Finished restoring cached corepack dependencies
6:21:08 PM: No npm workspaces detected
6:21:08 PM: Started restoring cached node modules
6:21:08 PM: Finished restoring cached node modules
6:21:08 PM: Installing npm packages using npm version 8.19.4
6:21:09 PM: npm WARN deprecated sourcemap-codec@1.4.8: Please use @jridgewell/sourcemap-codec instead
6:21:50 PM: added 288 packages, and audited 289 packages in 42s
6:21:50 PM: 93 packages are looking for funding
6:21:50 PM: run npm fund for details
6:21:50 PM: found 0 vulnerabilities
6:21:50 PM: npm packages installed
6:21:50 PM: Install dependencies script success
6:21:50 PM: Starting build script
6:21:51 PM: Detected 1 framework(s)
6:21:51 PM: β€œvite” at version β€œ3.1.4”
6:21:51 PM: Section completed: initializing
6:21:53 PM: ​
6:21:53 PM: Netlify Build
6:21:53 PM: ────────────────────────────────────────────────────────────────
6:21:53 PM: ​
6:21:53 PM: ❯ Version
6:21:53 PM: @netlify/build 29.11.6
6:21:53 PM: ​
6:21:53 PM: ❯ Flags
6:21:53 PM: baseRelDir: true
6:21:53 PM: buildId: 6474d0eb2837561ddaa2ecaa
6:21:53 PM: deployId: 6474d0eb2837561ddaa2ecac
6:21:53 PM: ​
6:21:53 PM: ❯ Current directory
6:21:53 PM: /opt/build/repo
6:21:53 PM: ​
6:21:53 PM: ❯ Config file
6:21:53 PM: No config file was defined: using default values.
6:21:53 PM: ​
6:21:53 PM: ❯ Context
6:21:53 PM: production
6:21:53 PM: ​
6:21:53 PM: Build command from Netlify app
6:21:53 PM: ────────────────────────────────────────────────────────────────
6:21:53 PM: ​
6:21:53 PM: $ CI= npm run build
6:21:53 PM: > citr-v8-project@8.0.0 build
6:21:53 PM: > vite build
6:21:53 PM: vite v3.1.4 building for production…
6:21:53 PM: transforming…
6:21:55 PM: βœ“ 88 modules transformed.
6:21:55 PM: rendering chunks…
6:21:55 PM: dist/index.html 0.44 KiB
6:21:55 PM: dist/assets/index.0f0f1391.css 4.12 KiB / gzip: 1.38 KiB
6:21:55 PM: dist/assets/index.a7316fdc.js 195.28 KiB / gzip: 61.90 KiB
6:21:55 PM: ​
6:21:55 PM: (build.command completed in 2.4s)
6:21:55 PM: ​
6:21:55 PM: Deploy site
6:21:55 PM: ────────────────────────────────────────────────────────────────
6:21:55 PM: ​
6:21:55 PM: Section completed: deploying
6:21:55 PM: ​
6:21:55 PM: Configuration error
6:21:55 PM: ────────────────────────────────────────────────────────────────
6:21:55 PM: ​
6:21:55 PM: Error message
6:21:55 PM: Deploy did not succeed: Deploy directory β€˜dist’ does not exist
6:21:55 PM: ​
6:21:55 PM: Resolved config
6:21:55 PM: build:
6:21:55 PM: command: CI= npm run build
6:21:55 PM: commandOrigin: ui
6:21:55 PM: environment:
6:21:55 PM: - CI
6:21:55 PM: publish: /opt/build/repo/dist
6:21:55 PM: publishOrigin: ui
6:21:56 PM: Caching artifacts
6:21:56 PM: Started saving node modules
6:21:56 PM: Finished saving node modules
6:21:56 PM: Started saving build plugins
6:21:56 PM: Finished saving build plugins
6:21:56 PM: Started saving corepack cache
6:21:56 PM: Finished saving corepack cache
6:21:56 PM: Started saving pip cache
6:21:56 PM: Finished saving pip cache
6:21:56 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)
6:21:56 PM: Started saving emacs cask dependencies
6:21:56 PM: Finished saving emacs cask dependencies
6:21:56 PM: Started saving maven dependencies
6:21:56 PM: Finished saving maven dependencies
6:21:56 PM: Started saving boot dependencies
6:21:56 PM: Finished saving boot dependencies
6:21:56 PM: Started saving rust rustup cache
6:21:56 PM: Finished saving rust rustup cache
6:21:56 PM: Started saving go dependencies
6:21:56 PM: Finished saving go dependencies
6:21:56 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
6:21:56 PM: Failing build: Failed to build site
6:21:57 PM: Finished processing build request in 55.824s

Now i have problem with dist directory.

@glejzermateusz The way that you have your project configured, your dist folder is being built into your src folder (and ending up at /src/dist/).

You’ve told Netlify to deploy /dist/ and that folder doesn’t exist.

You’ll either need to tell Netlify to deploy /src/dist/ or adjust your configuration so that it builds the /dist/ folder to the root.

To adjust your build configuration, inside your vite.config.js change:

FROM

export default defineConfig({
  plugins: [react()],
  root: "src",
});

TO

export default defineConfig({
  plugins: [react()],
  root: "src",
  build: {
    outDir: "../dist",
  },
});

As per the Vite documentation here: