Laravel Breeze+Vite启动Dev服务器报错:CLIENT_ENTRY文件不存在
解决Laravel Breeze + Vite执行
npm run dev时的CLIENT_ENTRY文件缺失报错 我使用Vite搭建了全新的Laravel Breeze项目,执行命令npm run dev时出现以下报错:
failed to load config from PATH/vite.config.js error when starting dev server: Error: cannot test case insensitive FS, CLIENT_ENTRY does not point to an existing file: PATH/dist/client/client.mjs at testCaseInsensitiveFS (PATH/node_modules/vite/dist/node-cjs/publicUtils.cjs:3420:15) at Object.<anonymous> (PATH/node_modules/vite/dist/node-cjs/publicUtils.cjs:3425:1) at Module._compile (node:internal/modules/cjs/loader:1126:14) at Module._extensions..js (node:internal/modules/cjs/loader:1180:10) at Object._require.extensions.<computed> [as .js] (file:///PATH/node_modules/vite/dist/node/chunks/dep-6b3a5aff.js:63517:17) at Module.load (node:internal/modules/cjs/loader:1004:32) at Function.Module._load (node:internal/modules/cjs/loader:839:12) at Module.require (node:internal/modules/cjs/loader:1028:19) at require (node:internal/modules/cjs/helpers:102:18) at Object.<anonymous> (PATH/node_modules/vite/index.cjs:7:31)
几周前执行相同操作还无异常,我的Vite配置文件如下:
import { defineConfig } from 'vite'; import laravel from 'laravel-vite-plugin'; export default defineConfig({ plugins: [ laravel({ input: [ 'resources/css/app.css', 'resources/js/app.js', ], refresh: true, }), ], });
解决方案
清理依赖缓存并重新安装
删除现有依赖和锁文件后重新安装,解决可能的依赖损坏问题:rm -rf node_modules package-lock.json npm install若使用Yarn,执行:
rm -rf node_modules yarn.lock yarn install匹配Vite与laravel-vite-plugin版本
Laravel Breeze对Vite及插件版本有兼容要求,检查当前版本是否匹配:npm list vite laravel-vite-plugin若版本不兼容,安装官方推荐的匹配版本(示例版本以Laravel 10为例,可根据项目调整):
npm install vite@^4.4.9 laravel-vite-plugin@^0.7.8 --save-dev临时创建缺失目录(应急方案)
若上述步骤无效,可手动创建缺失的目录临时恢复运行,但建议优先解决依赖问题:mkdir -p dist/client排查环境变量配置
检查项目根目录的.env文件,确保没有错误设置VITE相关环境变量导致路径指向异常。
内容的提问来源于stack exchange,提问作者PsKinggood
相关产品推荐
相关产品推荐

