Skip to content

fix: 修复 electron-vite 环境下 process.env.VITE_DEV_SERVER_URL 获取失败导致的启动白屏问题#7

Open
aidanHu wants to merge 2 commits intoMemeCalculate:mainfrom
aidanHu:fix/dev-server-url
Open

fix: 修复 electron-vite 环境下 process.env.VITE_DEV_SERVER_URL 获取失败导致的启动白屏问题#7
aidanHu wants to merge 2 commits intoMemeCalculate:mainfrom
aidanHu:fix/dev-server-url

Conversation

@aidanHu
Copy link

@aidanHu aidanHu commented Feb 26, 2026

问题描述

在运行 npm run dev 时,由于前端使用了 electron-vite 构建工具,开发服务器启动时注入的环境变量是 ELECTRON_RENDERER_URL,而不是原有的 VITE_DEV_SERVER_URL。这导致 main.ts 无法正确获取开发服务器的本地 URL,错误进入了查找本地打包后 index.html 的逻辑,最终引发 ERR_FILE_NOT_FOUND 的白屏报错。

修复内容

修改了 electron/main.ts 中的环境变量获取语句,增加了对 ELECTRON_RENDERER_URL 的兼容支持:
export const VITE_DEV_SERVER_URL = process.env['ELECTRON_RENDERER_URL'] || process.env['VITE_DEV_SERVER_URL']

该修复已在本地通过测试,执行 npm run dev 后可以正常渲染页面。

@aidanHu
Copy link
Author

aidanHu commented Feb 26, 2026

主要是在mac中运行的时候提示这个错误

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant