You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
At present, Vite always opinion Pre-Bundling format(ESM) code as single for Web App, but when use Vite in Electron's Renderer process, the standard ESM code can not wooks, because Electron does not support full-ESM format code.
constelectron=typeofrequire!=='undefined'// All exports module see https://www.electronjs.org -> API -> Renderer Process Modules
? require("electron")
: (functionnodeIntegrationWarn(){console.error(`If you need to use "electron" in the Renderer process, make sure that "nodeIntegration" is enabled in the Main process.`);return{// TODO: polyfill};}());// Proxy in Workerlet_ipcRenderer;if(typeofdocument==='undefined'){_ipcRenderer={};constkeys=['invoke','postMessage','send','sendSync','sendTo','sendToHost',// propertype'addListener','emit','eventNames','getMaxListeners','listenerCount','listeners','off','on','once','prependListener','prependOnceListener','rawListeners','removeAllListeners','removeListener','setMaxListeners',];for(constkeyofkeys){_ipcRenderer[key]=()=>{thrownewError('ipcRenderer doesn\'t work in a Web Worker.\n'+'You can see https://github.com/electron-vite/vite-plugin-electron/issues/69');};}}else{_ipcRenderer=electron.ipcRenderer;}export{electronasdefault};exportconstclipboard=electron.clipboard;exportconstcontextBridge=electron.contextBridge;exportconstcrashReporter=electron.crashReporter;exportconstipcRenderer=_ipcRenderer;exportconstnativeImage=electron.nativeImage;exportconstshell=electron.shell;exportconstwebFrame=electron.webFrame;exportconstdeprecate=electron.deprecate;
Vite Pre-Bundling ❌
import{__commonJS}from"./chunk-RSJERJUL.js";// browser-external:fsvarrequire_fs=__commonJS({"browser-external:fs"(exports,module){module.exports=Object.create(newProxy({},{get(_,key){if(key!=="__esModule"&&key!=="__proto__"&&key!=="constructor"&&key!=="splice"){console.warn(`Module "fs" has been externalized for browser compatibility. Cannot access "fs.${key}" in client code. See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`);}}}));}});// browser-external:pathvarrequire_path=__commonJS({"browser-external:path"(exports,module){module.exports=Object.create(newProxy({},{get(_,key){if(key!=="__esModule"&&key!=="__proto__"&&key!=="constructor"&&key!=="splice"){console.warn(`Module "path" has been externalized for browser compatibility. Cannot access "path.${key}" in client code. See http://vitejs.dev/guide/troubleshooting.html#module-externalized-for-browser-compatibility for more details.`);}}}));}});// node_modules/electron/index.jsvarrequire_electron=__commonJS({"node_modules/electron/index.js"(exports,module){varfs=require_fs();varpath=require_path();varpathFile=path.join(__dirname,"path.txt");functiongetElectronPath(){letexecutablePath;if(fs.existsSync(pathFile)){executablePath=fs.readFileSync(pathFile,"utf-8");}if(process.env.ELECTRON_OVERRIDE_DIST_PATH){returnpath.join(process.env.ELECTRON_OVERRIDE_DIST_PATH,executablePath||"electron");}if(executablePath){returnpath.join(__dirname,"dist",executablePath);}else{thrownewError("Electron failed to install correctly, please delete node_modules/electron and try installing again");}}module.exports=getElectronPath();}});exportdefaultrequire_electron();//# sourceMappingURL=electron.js.map
Suggested solution
Mybe we can support custom Pre-Bundling for Electron or others. :)
BTW, Electron Forge will be support Vite at v6.1.0. It faces the same as problem. electron/forge#3071
Description
At present, Vite always opinion Pre-Bundling format(ESM) code as single for Web App, but when use Vite in Electron's Renderer process, the standard ESM code can not wooks, because Electron does not support full-ESM format code.
So, we must bloc Pre-Bundling behavior by
optimizeDeps.exclude
for solution it.https://github.com/electron-vite/vite-plugin-electron-renderer#dependency-pre-bundling
https://github.com/electron-vite/vite-plugin-electron-renderer/blob/v0.12.1/examples/quick-start/vite.config.ts#L14-L23
e.g.
Expected(vite-plugin-electron-renderer) ✅
Vite Pre-Bundling ❌
Suggested solution
Mybe we can support custom Pre-Bundling for Electron or others. :)
BTW, Electron Forge will be support Vite at
v6.1.0
. It faces the same as problem.electron/forge#3071
Alternative
No response
Additional context
No response
Validations
The text was updated successfully, but these errors were encountered: