You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Vue 3生产构建报错:spawn vite ENOENT求助

解决Vite构建时出现'spawn vite ENOENT'错误的方案

问题背景

执行生产构建时触发以下错误:

Error while running task C:\xxxxx:build with message'spawn vite ENOENT'

环境信息:

  • Vue 3 + Vue UI
  • Node版本:v18.16.0
  • 使用Creative Tim的Vue Material Kit模板(带Bootstrap)
  • 开发模式可正常运行,仅构建生产版本时出错
  • 项目根目录的vite.config.js内容:
import { fileURLToPath, URL } from "url";

import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";

// https://vitejs.dev/config/
export default defineConfig({
  plugins: [vue()],
  resolve: {
    alias: {
      "@": fileURLToPath(new URL("./src", import.meta.url)),
    },
  },
});

可行解决步骤

1. 确认项目本地已安装Vite

开发模式可能依赖全局Vite,但构建生产版本需要本地项目依赖。在项目根目录执行:

npm list vite

若返回未安装提示,执行安装命令:

npm install vite --save-dev

2. 清理依赖缓存并重新安装

依赖损坏或缓存冲突可能导致路径识别问题,执行以下操作:

# Windows系统
rmdir /s /q node_modules && del package-lock.json
npm cache clean --force
npm install

# macOS/Linux系统
rm -rf node_modules package-lock.json
npm cache clean --force
npm install

3. 检查package.json的build脚本

确保package.json中的build命令正确调用Vite,正确配置如下:

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

修改后保存,重新尝试构建。

4. 跳过Vue UI,直接用命令行构建

Vue UI的环境配置可能存在异常,直接在项目根目录执行:

npm run build

观察命令行输出的详细错误,进一步定位问题。

5. 验证Node.js环境变量配置

确保Node.js的安装路径已添加到系统环境变量中,执行node -v确认命令行可正常识别Node。若无法识别,重新配置环境变量后重启终端和Vue UI。

内容的提问来源于stack exchange,提问作者Jean-Loup

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.19 22:52:41