“Build script returned non-zero exit code: 2” Vite build

trying to build a pretty simple single page react app. I coded it on replit which uses vite by default, and it builds locally fine. But everytime I try and build it on netlify, the build tab lights up with a green “success” block before changing over suddenly to failed. any ideas?


11:09:35 PM: build-image version: 3b96229e32b19cdf63f20dc1fc9331cd240c2d01 (focal)
11:09:35 PM: buildbot version: 3b96229e32b19cdf63f20dc1fc9331cd240c2d01
11:09:35 PM: Fetching cached dependencies
11:09:35 PM: Failed to fetch cache, continuing with build
11:09:35 PM: Starting to prepare the repo for build
11:09:36 PM: No cached dependencies found. Cloning fresh repo
11:09:36 PM: git clone --filter=blob:none https://github.com/ryguysir/Personal-Site-Streaming-Style
11:09:36 PM: Preparing Git Reference refs/heads/main
11:09:38 PM: Starting to install dependencies
11:09:38 PM: Python version set to 3.8
11:09:38 PM: Attempting Ruby version 2.7.2, read from environment
11:09:39 PM: Using Ruby version 2.7.2
11:09:40 PM: Started restoring cached go cache
11:09:40 PM: Finished restoring cached go cache
11:09:40 PM: go version go1.19.10 linux/amd64
11:09:40 PM: Using PHP version 8.0
11:09:41 PM: v18.16.0 is already installed.
11:09:42 PM: Now using node v18.16.0 (npm v9.5.1)
11:09:42 PM: Enabling Node.js Corepack
11:09:42 PM: Started restoring cached build plugins
11:09:42 PM: Finished restoring cached build plugins
11:09:42 PM: Started restoring cached corepack dependencies
11:09:42 PM: Finished restoring cached corepack dependencies
11:09:42 PM: No npm workspaces detected
11:09:42 PM: Started restoring cached node modules
11:09:42 PM: Finished restoring cached node modules
11:09:43 PM: Installing npm packages using npm version 9.5.1
11:09:45 PM: added 80 packages, and audited 81 packages in 2s
11:09:45 PM: 7 packages are looking for funding
11:09:45 PM:   run `npm fund` for details
11:09:45 PM: found 0 vulnerabilities
11:09:45 PM: npm packages installed
11:09:45 PM: Install dependencies script success
11:09:45 PM: Starting build script
11:09:46 PM: Detected 1 framework(s)
11:09:46 PM: "vite" at version "4.3.9"
11:09:46 PM: Section completed: initializing
11:09:48 PM: ​
11:09:48 PM: Netlify Build                                                 
11:09:48 PM: ────────────────────────────────────────────────────────────────
11:09:48 PM: ​
11:09:48 PM: ❯ Version
11:09:48 PM:   @netlify/build 29.12.1
11:09:48 PM: ​
11:09:48 PM: ❯ Flags
11:09:48 PM:   baseRelDir: true
11:09:48 PM:   buildId: 6488081e7cb1a2638e31b45e
11:09:48 PM:   deployId: 6488081e7cb1a2638e31b460
11:09:48 PM: ​
11:09:48 PM: ❯ Current directory
11:09:48 PM:   /opt/build/repo
11:09:48 PM: ​
11:09:48 PM: ❯ Config file
11:09:48 PM:   No config file was defined: using default values.
11:09:48 PM: ​
11:09:48 PM: ❯ Context
11:09:48 PM:   production
11:09:48 PM: ​
11:09:48 PM: Build command from Netlify app                                
11:09:48 PM: ────────────────────────────────────────────────────────────────
11:09:48 PM: ​
11:09:48 PM: $ CI= npm run build
11:09:48 PM: > react-javascript@1.0.0 build
11:09:48 PM: > vite build
11:09:48 PM: vite v4.3.9 building for production...
11:09:48 PM: transforming...
11:09:50 PM: ✓ 166 modules transformed.
11:09:50 PM: rendering chunks...
11:09:50 PM: computing gzip size...
11:09:50 PM: dist/index.html                   1.08 kB │ gzip:  0.63 kB
11:09:50 PM: dist/assets/index-88aa9a55.css   18.57 kB │ gzip:  5.19 kB
11:09:50 PM: dist/assets/index-e03f8c65.js   251.66 kB │ gzip: 77.61 kB
11:09:50 PM: ✓ built in 1.81s
11:09:50 PM: ​
11:09:50 PM: (build.command completed in 2.6s)
11:09:50 PM: ​
11:09:50 PM: Deploy site                                                   
11:09:50 PM: ────────────────────────────────────────────────────────────────
11:09:50 PM: ​
11:09:50 PM: Section completed: deploying
11:09:50 PM: ​
11:09:50 PM: Configuration error                                           
11:09:50 PM: ────────────────────────────────────────────────────────────────
11:09:50 PM: ​
11:09:50 PM:   Error message
11:09:50 PM:   Deploy did not succeed: Deploy directory 'build' does not exist
11:09:50 PM: ​
11:09:50 PM:   Resolved config
11:09:50 PM:   build:
11:09:50 PM:     command: CI= npm run build
11:09:50 PM:     commandOrigin: ui
11:09:50 PM:     publish: /opt/build/repo/build
11:09:50 PM:     publishOrigin: ui
11:09:51 PM: Caching artifacts
11:09:51 PM: Started saving node modules
11:09:51 PM: Finished saving node modules
11:09:51 PM: Started saving build plugins
11:09:51 PM: Finished saving build plugins
11:09:51 PM: Started saving corepack cache
11:09:51 PM: Finished saving corepack cache
11:09:51 PM: Started saving pip cache
11:09:51 PM: Finished saving pip cache
11:09:51 PM: Started saving emacs cask dependencies
11:09:52 PM: Failed during stage 'building site': Build script returned non-zero exit code: 2 (https://ntl.fyi/exit-code-2)
11:09:51 PM: Finished saving emacs cask dependencies
11:09:51 PM: Started saving maven dependencies
11:09:51 PM: Finished saving maven dependencies
11:09:51 PM: Started saving boot dependencies
11:09:51 PM: Finished saving boot dependencies
11:09:51 PM: Started saving rust rustup cache
11:09:51 PM: Finished saving rust rustup cache
11:09:51 PM: Started saving go dependencies
11:09:51 PM: Finished saving go dependencies
11:09:52 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
11:09:52 PM: Failing build: Failed to build site
11:09:52 PM: Finished processing build request in 16.978s

@ryguysir The error is pretty clear about what the issue is:

11:09:50 PM:   Error message
11:09:50 PM:   Deploy did not succeed: Deploy directory 'build' does not exist
11:09:50 PM: ​
11:09:50 PM:   Resolved config
11:09:50 PM:   build:
11:09:50 PM:     command: CI= npm run build
11:09:50 PM:     commandOrigin: ui
11:09:50 PM:     publish: /opt/build/repo/build
11:09:50 PM:     publishOrigin: ui

You’ve got your site configured to deploy a folder called build and it doesn’t exist.

Since you mention that you’re using vite you likely want to deploy dist.

2 Likes