vite-plugin-ai-fixer
v1.0.0
Published
Vite plugin that captures build errors and provides AI-powered solutions
Downloads
134
Maintainers
Readme
vite-plugin-ai-fixer
Vite 构建错误 AI 分析插件。在 vite build 失败时,自动捕获错误并通过 LLM 分析根因,输出解决方案到终端。
特性
- 🔍 自动捕获构建错误(模块解析失败、TypeScript 错误、CSS 错误等)
- 📝 读取源文件上下文,提供准确的代码片段
- 🤖 通过 LLM 分析根因并生成修复方案
- 🎨 彩色终端输出,清晰直观
- 🔌 兼容所有 OpenAI 兼容接口
安装
pnpm add -D vite-plugin-ai-fixer使用
在 vite.config.ts 中配置:
import { defineConfig } from "vite";
import aiFixer from "vite-plugin-ai-fixer";
export default defineConfig({
plugins: [
aiFixer({
apiKey: "your-api-key", // 必填
model: "gpt-4o-mini", // 必填
baseUrl: "https://api.openai.com/v1", // 可选,默认 OpenAI
}),
],
});使用 Ollama 本地模型
aiFixer({
apiKey: "ollama",
model: "qwen2.5-coder",
baseUrl: "http://localhost:11434/v1",
});使用 DeepSeek
aiFixer({
apiKey: "your-deepseek-key",
model: "deepseek-chat",
baseUrl: "https://api.deepseek.com/v1",
});配置项
| 参数 | 类型 | 必填 | 默认值 | 说明 |
| -------------- | --------- | ----- | --------------------------- | ---------------- |
| apiKey | string | ✅ | - | LLM API Key |
| model | string | ✅ | - | 模型名称 |
| baseUrl | string | ❌ | https://api.openai.com/v1 | API 地址 |
| locale | 'zh-CN' | 'en' | ❌ | zh-CN |
| contextLines | number | ❌ | 4 | 代码上下文行数 |
| timeout | number | ❌ | 30000 | LLM 调用超时(ms) |
| maxErrors | number | ❌ | 10 | 最多分析错误数 |
| disable | boolean | ❌ | false | 是否禁用插件 |
输出示例
text
开始 AI 分析...
\r✅ AI 分析完成 (9.2s)
🤖 vite-plugin-ai-fixer 分析结果
📄 /Users/fangyan/WorkBuddy/20260416190835/agent-projects-100/projects/test-ai-fixer/src/App.tsx:6:42
🔍 根因 (置信度 100%):
代码中导入了不存在的包 'non-existent-package',该包未在项目中安装或不存在于 npm 仓库中
💡 解决方案:
1. 代码修改: 删除对不存在包的导入语句
┌────────────────────────────────────────────┐
│ import reactLogo from './assets/react.svg' │
│ import viteLogo from './assets/vite.svg' │
│ import heroImg from './assets/hero.png' │
│ import './App.css' │
└────────────────────────────────────────────┘
2. 执行命令: 如果确实需要该包,请先安装它(但此包名看起来是示例名称)
┌──────────────────────────────────┐
│ npm install non-existent-package │
└──────────────────────────────────┘
📋 总结:
该错误是由于导入了不存在的 npm 包导致的。最直接的解决方案是删除第6行的导入语句,因为 'non-existent-package' 看起来是一个示例或占位符包名,并非真实存在的依赖。
⏳ Vite 原始错误信息将在 2 秒后显示...