Vite build Netlify error

User
Vue netlify build failed shows vite build not found
Assistant
If you're deploying a Vue 3 project to Netlify and seeing an error like:

Command failed with exit code 1: vite build not found

It typically means Netlify is unable to recognize or run the `vite build` command. Here's how to fix it:

### **Step-by-step fix:**

#### **1. Ensure `vite` is installed**
Make sure Vite is added as a dependency in your `package.json`:

"devDependencies": {
  "vite": "^6.2.6"
}

If it's missing, run:

yarn add -D vite
# or
npm install --save-dev vite

#### **2. Verify your `build` script**
In `package.json`, make sure you have:

"scripts": {
  "build": "vite build"
}

Netlify runs `npm run build` or `yarn build`, so this script **must exist**.

#### **3. Set Netlify build command and publish directory**

In your Netlify settings:

– **Build Command**: `yarn build` or `npm run build`
– **Publish directory**: `dist`

Or in `netlify.toml`:

[build]
  command = "yarn build"
  publish = "dist"

#### **4. If still failing, add a Netlify plugin**
Sometimes the environment doesn’t install dev dependencies. Force it:

In your `netlify.toml`:

[build.environment]
  NODE_ENV = "development"

Or add a `.npmrc` file:

production=false

If you've done all this and still face issues, drop your `package.json` and Netlify logs and I’ll help debug it!

User
{
"name": "frontend",
"version": "0.0.0",
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build",
"preview": "vite preview"
},
"dependencies": {
"@mdi/font": "^7.4.47",
"@vueup/vue-quill": "^1.2.0",
"apexcharts": "^4.5.0",
"axios": "^1.8.1",
"firebase": "^11.4.0",
"firebase-admin": "^13.2.0",
"nprogress": "^0.2.0",
"pinia": "^3.0.1",
"vee-validate": "^4.15.0",
"vite": "^6.2.6",
"vue": "^3.5.13",
"vue-router": "^4.5.0",
"vue-tabler-icons": "^2.21.0",
"vue3-apexcharts": "^1.8.0",
"vue3-perfect-scrollbar": "^2.0.0",
"vue3-print-nb": "^0.1.4",
"vuetify": "^3.7.15"
},
"devDependencies": {
"@tsconfig/node22": "^22.0.0",
"@types/jsdom": "^21.1.7",
"@types/node": "^22.13.4",
"@vitejs/plugin-vue": "^5.2.1",
"@vitejs/plugin-vue-jsx": "^4.1.1",
"@vitest/eslint-plugin": "1.1.31",
"@vue/eslint-config-prettier": "^10.2.0",
"@vue/eslint-config-typescript": "^14.4.0",
"@vue/test-utils": "^2.4.6",
"@vue/tsconfig": "^0.7.0",
"eslint": "^9.20.1",
"eslint-plugin-vue": "^9.32.0",
"jiti": "^2.4.2",
"jsdom": "^26.0.0",
"npm-run-all2": "^7.0.2",
"prettier": "^3.5.1",
"sass-embedded": "^1.86.0",
"typescript": "~5.7.3",
"vite-plugin-vue-devtools": "^7.7.2",
"vitest": "^3.0.5",
"vue-tsc": "^2.2.8"
}
}
$ yarn build
6:55:11 PM: yarn run v1.22.22
6:55:11 PM: $ vite build
6:55:11 PM: /bin/sh: 1: vite: not found
6:55:11 PM: error Command failed with exit code 127. (https://ntl.fyi/exit-code-127)
6:55:11 PM: info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
6:55:11 PM: ​
6:55:11 PM: "build.command" failed
6:55:11 PM: ────────────────────────────────────────────────────────────────
6:55:11 PM: ​
6:55:11 PM: Error message
6:55:11 PM: Command failed with exit code 127: yarn build (https://ntl.fyi/exit-code-127)
6:55:11 PM: ​
6:55:11 PM: Error location
6:55:11 PM: In Build command from Netlify app:
6:55:11 PM: yarn build
6:55:11 PM: ​
6:55:11 PM: Resolved config
6:55:11 PM: build:
6:55:11 PM: base: /opt/build/repo/dist
6:55:11 PM: command: yarn build
6:55:11 PM: commandOrigin: ui
6:55:11 PM: publish: /opt/build/repo/dist
6:55:11 PM: publishOrigin: ui
6:55:11 PM: redirects:
6:55:12 PM: – from: /*
status: 200
to: /index.html
Assistant
The error:

/bin/sh: 1: vite: not found

means Netlify cannot find the `vite` binary when running `yarn build`, even though it's listed in your `dependencies`.

### **Here's how to fix it:**

#### ✅ 1. Move `vite` to `devDependencies`
Since `vite` is a **build tool**, it should go under `devDependencies`:

**Fix:**
In your `package.json`, move this:

"vite": "^6.2.6"

from `dependencies` to `devDependencies`.

So your `devDependencies` should now include:

"vite": "^6.2.6"

#### ✅ 2. Force Netlify to install dev dependencies
Add this to your `netlify.toml` file (or create one if you don’t have it):

[build.environment]
  NODE_ENV = "development"

Alternatively, add a `.npmrc` or `.yarnrc` file with:

production=false

This ensures Netlify doesn’t skip installing dev dependencies.

#### ✅ 3. (Optional) Clean deploy
After the changes:

– Commit and push your changes.
– Trigger a new deploy on Netlify (or hit "Clear cache and deploy site").

Let me know if you want a `netlify.toml` sample or deploy preview config as well.

Leave a Comment

Your email address will not be published. Required fields are marked *