Vue项目启动报错:无法加载vite.config.js及esbuild服务停止求助
Vue + Vite启动报错:无法加载vite.config.js且esbuild服务停止
我的Vue项目昨天还能正常运行,今天启动时直接报错,提示无法加载C:\Users\Desktop\Learn\Project\vuejs-frontend\vite.config.js,启动开发服务器时出现「The service was stopped」错误,堆栈信息指向esbuild相关文件。
我的vite.config.js内容
import { fileURLToPath, URL } from "node: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)), }, }, });
完整报错信息
failed to load config from C:\Users\Desktop\Learn\Project\vuejs-frontend\vite.config.js error when starting dev server: Error: The service was stopped at C:\Users\Desktop\Learn\Project\vuejs-frontend\node_modules\esbuild\lib\main.js:1337:25 at C:\Users\Desktop\Learn\Project\vuejs-frontend\node_modules\esbuild\lib\main.js:666:9 at Socket.afterClose (C:\Users\Desktop\Learn\Project\vuejs-frontend\node_modules\esbuild\lib\main.js:644:7) at Socket.emit (node:events:539:35) at endReadableNT (node:internal/streams/readable:1345:12) at processTicksAndRejections (node:internal/process/task_queues:83:21)
解决建议
清理依赖缓存并重装
删除node_modules文件夹和package-lock.json(或yarn.lock),再重新安装依赖:# Windows用户 rd /s /q node_modules del package-lock.json npm install # Mac/Linux用户 rm -rf node_modules package-lock.json npm install清除Vite缓存
删除项目根目录下的.vite缓存文件夹,再重启项目:# Windows用户 rd /s /q .vite npm run dev # Mac/Linux用户 rm -rf .vite npm run dev检查Node.js版本
确认Node.js版本符合Vite要求(Vite 4.x+建议14.18+、16+版本),用node -v查看版本,过低则升级到稳定版。检查文件权限
右键vite.config.js选择「属性」,取消「只读」选项,确保当前用户拥有文件的读写权限。锁定esbuild稳定版本
在package.json的devDependencies中指定一个稳定的esbuild版本,比如:"devDependencies": { "esbuild": "^0.17.19" }执行
npm install后重启项目。关闭冲突进程
用任务管理器关闭所有Node.js相关进程,再重新启动项目,避免端口或资源占用冲突。
内容的提问来源于stack exchange,提问作者Precious Chika
相关产品推荐
相关产品推荐

