Build a Desktop App with Electron, React, Vite, and TypeScript
Modern web tooling makes it surprisingly easy to build cross-platform desktop apps. By combining Electron, React, Vite, and TypeScript, you can create fast desktop applications using familiar web technologies.
In this guide, we’ll start with a fresh Vite React project and turn it into an Electron desktop app step by step.
1. Create the Vite Project
First create a new Vite React + TypeScript project (or any other framework you want):
npm create vite@latest my-electron-app
npm create vite@latest my-electron-app
At this point your package.json looks like this:
{
"name": "my-electron-app",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"react": "^19.2.0",
"react-dom": "^19.2.0"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"@types/node": "^24.10.1",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.1",
"eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"globals": "^16.5.0",
"typescript": "~5.9.3",
"typescript-eslint": "^8.48.0",
"vite": "^7.3.1"
}
}
{
"name": "my-electron-app",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"react": "^19.2.0",
"react-dom": "^19.2.0"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"@types/node": "^24.10.1",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.1",
"eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"globals": "^16.5.0",
"typescript": "~5.9.3",
"typescript-eslint": "^8.48.0",
"vite": "^7.3.1"
}
}
2. Install Electron and Helper Tools
Now install Electron and a few tools that make development smoother.
npm install electron concurrently wait-on cross-env
npm install electron concurrently wait-on cross-env
These packages solve common problems:
- Electron → runs the desktop application
- concurrently → run Vite and Electron together
- wait-on → ensures Electron waits for the dev server
- cross-env → sets environment variables cross-platform
3. Update package.json
Next, update your scripts and dependencies so Electron and Vite run together.
Add a entry point for Electron:
"main": "electron/main.js"
Replace the dev script and add a new electron script:
"dev": "concurrently "vite" "npm:electron"",
"electron": "wait-on http://localhost:5173 && cross-env NODE_ENV=development electron ."
"dev": "concurrently "vite" "npm:electron"",
"electron": "wait-on http://localhost:5173 && cross-env NODE_ENV=development electron ."
Your package.json should now look like this:
{
"name": "my-electron-app",
"private": true,
"version": "0.0.0",
"type": "module",
"main": "electron/main.js",
"scripts": {
"dev": "concurrently "vite" "npm:electron"",
"electron": "wait-on http://localhost:5173 && cross-env NODE_ENV=development electron .",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"concurrently": "^9.2.1",
"cross-env": "^10.1.0",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"wait-on": "^9.0.4"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"@types/node": "^24.10.1",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.1",
"electron": "^40.8.0",
"eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"globals": "^16.5.0",
"typescript": "~5.9.3",
"typescript-eslint": "^8.48.0",
"vite": "^7.3.1"
}
}
{
"name": "my-electron-app",
"private": true,
"version": "0.0.0",
"type": "module",
"main": "electron/main.js",
"scripts": {
"dev": "concurrently "vite" "npm:electron"",
"electron": "wait-on http://localhost:5173 && cross-env NODE_ENV=development electron .",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"concurrently": "^9.2.1",
"cross-env": "^10.1.0",
"react": "^19.2.0",
"react-dom": "^19.2.0",
"wait-on": "^9.0.4"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"@types/node": "^24.10.1",
"@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.1",
"electron": "^40.8.0",
"eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"globals": "^16.5.0",
"typescript": "~5.9.3",
"typescript-eslint": "^8.48.0",
"vite": "^7.3.1"
}
}
What changed?
We added:
"main": "electron/main.js"→ Electron entry point- a dev script that runs Vite and Electron simultaneously
- a script that waits for the Vite server before launching Electron
Now running:
npm run dev
npm run dev
will start both Vite and Electron in DEV-mode automatically.
4. Create the Electron Main Process
Next create the folder electron in the root. Inside that folder create the entry file main.js with the following code:
{
const win = new BrowserWindow({
width: 800,
height: 600,
});
// DEV
if (process.env.NODE_ENV === "development") {
win.loadURL("http://localhost:5173/");
}
// PROD
else {
win.loadFile("dist/index.html");
}
};
app.whenReady().then(() => {
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});” data-toggle-ms=”1200″ aria-label=”Copy code” data-nosnippet=”” class=”code-copy-btn absolute right-3 top-3 size-8 p-1.5 flex items-center justify-center bg-black/50 text-white rounded-md transition-colors duration-200 cursor-pointer hover:bg-black/70″>
import { app, BrowserWindow } from "electron";
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600,
});
// DEV
if (process.env.NODE_ENV === "development") {
win.loadURL("http://localhost:5173/");
}
// PROD
else {
win.loadFile("dist/index.html");
}
};
app.whenReady().then(() => {
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
import { app, BrowserWindow } from "electron";
const createWindow = () => {
const win = new BrowserWindow({
width: 800,
height: 600,
});
// DEV
if (process.env.NODE_ENV === "development") {
win.loadURL("http://localhost:5173/");
}
// PROD
else {
win.loadFile("dist/index.html");
}
};
app.whenReady().then(() => {
createWindow();
app.on("activate", () => {
if (BrowserWindow.getAllWindows().length === 0) {
createWindow();
}
});
});
app.on("window-all-closed", () => {
if (process.platform !== "darwin") {
app.quit();
}
});
This file is the Electron main process responsible for:
- creating the application window
- loading the Vite dev server during development
- loading the built files in production
5. Fix Paths for Production
When Electron loads the built app, paths must be relative.
Update vite.config.ts:
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
base: "./", // relative paths for Electron
})
import { defineConfig } from 'vite'
import react from '@vitejs/plugin-react'
// https://vite.dev/config/
export default defineConfig({
plugins: [react()],
base: "./", // relative paths for Electron
})
This ensures the built files work correctly when opened locally by Electron.
6. Run the App
Start development mode:
npm run dev
npm run dev
This will:
- start the Vite dev server
- wait until it’s ready
- launch Electron
- open your React app in a desktop window
Final Result
You now have a desktop app powered by:
- React for UI
- Vite for fast development
- TypeScript for type safety
- Electron for cross-platform desktop support
And the development workflow remains exactly like a normal web project.


