0

i have a challenge since 3 days and even chatGpt couldn't resolve my issue :) I have a react/capacitor/electron app packaged with vite to build. Everything ok for capacitor and Mac/Linux Electron. But it fails on Windows package production.

After installing package and electron launch, i have a blanck page with C: content not available.

I am using electron-builder for this.

Package.json:

{
  "name": "test",
  "private": true,
  "version": "1.0.0",
  "type": "module",
  "main": "./electron/main.js",
  "description": "Test",
  "scripts": {
    "clean": "rm -rf dist dist-electron",
    "start": "vite",
    "build": "tsc -b && vite build",
    "build:electron": "npm run clean && npm run build && electron-builder",
    "build:development": "tsc -b && vite build --mode development",
    "preview": "vite preview",
    "electron": "electron .",
  },
  "dependencies": {
    "@capacitor/android": "^7.2.0",
    "@capacitor/cli": "^7.2.0",
    "@capacitor/core": "^7.2.0",
    "@capacitor/ios": "^7.4.2",
    "@emotion/react": "^11.14.0",
    "@emotion/styled": "^11.14.0",
    "@fontsource/inter": "^5.2.6",
    "@hookform/resolvers": "^5.0.1",
    "@mui/material": "^7.0.2",
    "@storybook/addon-themes": "^9.0.8",
    "@tanstack/react-query": "^5.76.0",
    "@tanstack/react-query-devtools": "^5.76.0",
    "@tanstack/react-virtual": "^3.13.10",
    "electron-log": "^5.4.0",
    "i18next": "^25.2.0",
    "i18next-browser-languagedetector": "^8.1.0",
    "lucide-react": "^0.503.0",
    "pdfjs-dist": "^5.3.93",
    "react": "^19.0.0",
    "react-code-input": "^3.10.1",
    "react-dom": "^19.0.0",
    "react-hook-form": "^7.56.3",
    "react-i18next": "^15.5.1",
    "react-pdf": "^10.0.1",
    "react-router-dom": "^7.5.2",
    "zod": "^3.24.4"
  },
  "devDependencies": {
   ...
    "electron": "^35.2.1",
    "electron-builder": "^26.0.12",
    ...
    "typescript": "~5.7.2",
    "typescript-eslint": "^8.32.0",
    "vite": "^6.3.1",
    "vitest": "^3.1.3"
  },
  "eslintConfig": {
    "extends": [
      "plugin:storybook/recommended"
    ]
  },
  "overrides": {
    "storybook": "$storybook"
  }
}

electron-build conf:

{
  "appId": "com.test.app",
  "asar": true,
  "asarUnpack": ["**/*.node"],
  "directories": {
    "output": "dist-electron"
  },
  "files": ["dist/**/*", "electron/**/*", "package.json"],
  "linux": {
    "category": "Utility",
    "target": ["AppImage", "deb", "tar.gz"]
  },
  "mac": {
    "category": "public.app-category.utilities",
    "target": ["dmg", "zip"]
  },
  "nsis": {
    "oneClick": false,
    "perMachine": true,
    "allowToChangeInstallationDirectory": true,
    "uninstallDisplayName": "Test"
  },
  "win": {
    "target": ["nsis", "zip"],
    "icon": "dist/assets/image_default_doc_test-D9Mxtk0U.png"
  }
}
import { BrowserWindow, app } from 'electron';
import log from 'electron-log';
import path from 'node:path';
import process from 'node:process';

const windows = [];

function createWindow() {
  const mainWindow = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      contextIsolation: true,
      nodeIntegration: true
    }
  });

  const indexHtmlPath = path.join(app.getAppPath(), 'dist', 'index.html');
  const devUrl = 'http://localhost:5173';
  if (app.isPackaged) {
    mainWindow.loadFile(indexHtmlPath);
  } else {
    mainWindow.loadURL(devUrl);
    mainWindow.webContents.openDevTools();
  }
  windows.push(mainWindow);
}

app.whenReady().then(() => {
  createWindow();
  log.info('Electron is ready');
});

app.on('window-all-closed', () => {
  if (process.platform !== 'darwin') app.quit();
});

process.on('uncaughtException', (err) => {
  log.error('Uncaught Exception:', err);
});

process.on('unhandledRejection', (reason, promise) => {
  log.error('Unhandled Rejection at:', promise, 'reason:', reason);
});

structure:

  • electron: main.js
  • src: React sources
  • dist: vite build
  • dist-electron: Electron out build

I try many configuration for devprod url: path.join(app.getAppPath(), 'dist', 'index.html') ...

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.