Build failed using vite+react

i have my app that was initially using webpack but i changed to vite today everything was simple but the part where deploying gave me error like

9:17:58 PM: ────────────────────────────────────────────────────────────────
9:17:58 PM: 1. Build command from Netlify app
9:17:58 PM: ────────────────────────────────────────────────────────────────
9:17:58 PM: ​
9:17:58 PM: $ npm run build
9:17:59 PM: > [email protected] build
9:17:59 PM: > vite build
9:17:59 PM: vite v2.8.4 building for production…
9:17:59 PM: transforming…
9:18:01 PM: ✓ 39 modules transformed.
9:18:01 PM: rendering chunks…
9:18:01 PM: dist/index.html 0.95 KiB
9:18:01 PM: dist/assets/index.4622ad7d.js 5.24 KiB / gzip: 1.76 KiB
9:18:01 PM: dist/assets/index.fcb37d1a.css 1.74 KiB / gzip: 0.76 KiB
9:18:01 PM: dist/assets/vendor.577e29cb.js 133.13 KiB / gzip: 43.06 KiB
9:18:01 PM: ​
9:18:01 PM: (build.command completed in 3s)
9:18:01 PM: ​
9:18:01 PM: ────────────────────────────────────────────────────────────────
9:18:01 PM: 2. Deploy site
9:18:01 PM: ────────────────────────────────────────────────────────────────
9:18:01 PM: ​
9:18:01 PM: ​
9:18:01 PM: ────────────────────────────────────────────────────────────────
9:18:01 PM: Configuration error
9:18:01 PM: ────────────────────────────────────────────────────────────────
9:18:01 PM: ​
9:18:01 PM: Error message
9:18:01 PM: Deploy did not succeed: Deploy directory ‘build’ does not exist
9:18:01 PM: ​
9:18:01 PM: Resolved config
9:18:01 PM: build:
9:18:01 PM: command: npm run build
9:18:01 PM: commandOrigin: ui
9:18:01 PM: publish: /opt/build/repo/build
9:18:01 PM: publishOrigin: ui
9:18:02 PM: Caching artifacts
9:18:02 PM: Started saving node modules
9:18:02 PM: Finished saving node modules
9:18:02 PM: Started saving build plugins
9:18:02 PM: Finished saving build plugins
9:18:02 PM: Started saving pip cache
9:18:02 PM: Finished saving pip cache
9:18:02 PM: Started saving emacs cask dependencies
9:18:02 PM: Finished saving emacs cask dependencies
9:18:02 PM: Started saving maven dependencies
9:18:02 PM: Finished saving maven dependencies
9:18:02 PM: Started saving boot dependencies
9:18:02 PM: Finished saving boot dependencies
9:18:02 PM: Started saving rust rustup cache
9:18:02 PM: Finished saving rust rustup cache
9:18:02 PM: Started saving go dependencies
9:18:02 PM: Finished saving go dependencies
9:18:04 PM: Build failed due to a user error: Build script returned non-zero exit code: 2
9:18:04 PM: Creating deploy upload records
9:18:05 PM: Failing build: Failed to build site
9:18:05 PM: Failed during stage ‘building site’: Build script returned non-zero exit code: 2
9:18:05 PM: Finished processing build request in 22.724321626s

the site is working fine in local host and i can build and preview in my system and i have no idea what is error means

Hey @pranav

This deploy has failed because…

The directory build does not exist because Vite builds to the dist directory as shown in these lines

Try changing the publish directory to dist and deploy again.

Create React App does use build as the output directory, but many others (including Vite) use dist (and there is usually an option to specify a directory name should you want something else.)

1 Like