{"id":15597,"library":"electron-vite","title":"Electron Vite Build Tooling","description":"electron-vite is a specialized build toolchain for Electron applications, leveraging the fast development experience of Vite. It streamlines the development process for Electron's main, preload, and renderer processes by providing pre-configured setups and a unified configuration API. The current stable version is 5.0.0, with beta releases for version 6.0.0 actively under development, indicating a moderate to rapid release cadence for new features and improvements. Key differentiators include its tight integration with Vite for all three Electron process types, simplified configuration, and out-of-the-box support for TypeScript and modern web development practices, making it a powerful alternative to more manual or less integrated build setups.","status":"active","version":"5.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/alex8088/electron-vite","tags":["javascript","electron","vite","cli","plugin","typescript"],"install":[{"cmd":"npm install electron-vite","lang":"bash","label":"npm"},{"cmd":"yarn add electron-vite","lang":"bash","label":"yarn"},{"cmd":"pnpm add electron-vite","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Core build tool that electron-vite extends and builds upon. Required as a peer dependency.","package":"vite","optional":false},{"reason":"Used for fast TypeScript/JavaScript transpilation. Required as a peer dependency.","package":"@swc/core","optional":false}],"imports":[{"note":"For `electron.vite.config.ts` files, `defineConfig` is imported directly from the main `electron-vite` package since v4. Importing from `@electron-vite/config` is incorrect for this package.","wrong":"import { defineConfig } from '@electron-vite/config'","symbol":"defineConfig","correct":"import { defineConfig } from 'electron-vite'"},{"note":"Standard Node.js `path.resolve` is commonly used within `electron-vite` configurations for robust path management, ensuring correct absolute paths for entries and outputs.","symbol":"resolve","correct":"import { resolve } from 'path'"},{"note":"Type import for defining and extending the Electron-Vite configuration object when working with TypeScript.","symbol":"UserConfig","correct":"import { UserConfig } from 'electron-vite'"}],"quickstart":{"code":"import { defineConfig } from 'electron-vite'\nimport { resolve } from 'path'\n\nexport default defineConfig({\n  main: {\n    // Main process build configuration\n    build: {\n      lib: {\n        entry: 'src/main/index.ts',\n        formats: ['cjs']\n      },\n      outDir: 'dist/main',\n      rollupOptions: {\n        external: ['electron'] // Prevent bundling electron itself\n      }\n    }\n  },\n  preload: {\n    // Preload script build configuration\n    build: {\n      lib: {\n        entry: 'src/preload/index.ts',\n        formats: ['cjs']\n      },\n      outDir: 'dist/preload',\n      rollupOptions: {\n        external: ['electron']\n      }\n    }\n  },\n  renderer: {\n    // Renderer process build configuration\n    root: '.', // Relative to electron.vite.config.ts\n    build: {\n      outDir: 'dist/renderer',\n      rollupOptions: {\n        // Example: externalize some renderer dependencies if needed\n        external: []\n      }\n    }\n  }\n})\n","lang":"typescript","description":"This quickstart demonstrates a typical `electron.vite.config.ts` configuration, setting up separate build processes for Electron's main, preload, and renderer scripts using `defineConfig`."},"warnings":[{"fix":"Upgrade your Node.js installation to a compatible version (e.g., Node.js v20.19.0 or v22.12.0 or newer) using `nvm` or a similar tool.","message":"Node.js engine requirements have been updated. Your environment must meet `^20.19.0 || >=22.12.0` to ensure compatibility and prevent build failures or unexpected runtime issues.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Install the required peer dependencies: `npm install -D vite@latest @swc/core@latest` (or yarn/pnpm equivalent), ensuring versions match the peer dependency range (`vite`: `^5.0.0 || ^6.0.0 || ^7.0.0`, `@swc/core`: `^1.0.0`).","message":"`electron-vite` relies on `vite` and `@swc/core` as peer dependencies. These packages must be explicitly installed in your project at compatible versions; otherwise, you may encounter warnings or build errors.","severity":"gotcha","affected_versions":">=4.0.0"},{"fix":"Always consult the `CHANGELOG.md` for the specific version you are upgrading to and follow the migration guide closely to adapt your `electron.vite.config.ts` and project setup.","message":"Major version changes (e.g., from v4 to v5, and upcoming v6) typically introduce breaking changes to the configuration API, internal build processes, or required project structure. Direct upgrades without checking may lead to errors.","severity":"breaking","affected_versions":">=5.0.0"},{"fix":"Use Node.js's `path.resolve(__dirname, 'your/relative/path')` or `path.join(process.cwd(), 'your/path')` to ensure absolute paths are consistently used across different environments and build steps.","message":"Incorrect path resolution within the `electron.vite.config.ts` can cause modules to be unresolvable during the build process, especially for entry points or static assets. Relative paths can be ambiguous.","severity":"gotcha","affected_versions":">=4.0.0"}],"env_vars":null,"last_verified":"2026-04-21T00:00:00.000Z","next_check":"2026-07-20T00:00:00.000Z","problems":[{"fix":"Upgrade your Node.js environment to a version within the specified range, e.g., `nvm install 20.19.0 && nvm use 20.19.0`.","cause":"Your current Node.js version is incompatible with the installed electron-vite package.","error":"Error: The installed Node.js version (vX.Y.Z) does not meet electron-vite's requirements (^20.19.0 || >=22.12.0)."},{"fix":"Install Vite by running `npm install -D vite@latest` or `yarn add -D vite@latest` in your project root.","cause":"`vite` is a peer dependency and must be explicitly installed in your project's `devDependencies`.","error":"Error: Cannot find module 'vite' or 'vite/package.json' from 'path/to/node_modules/electron-vite'"},{"fix":"Ensure your import statement is `import { defineConfig } from 'electron-vite'` and verify that `electron-vite` is correctly installed. Clear `node_modules` and reinstall if necessary.","cause":"This error often indicates that `defineConfig` was not correctly imported from `electron-vite`, or there's a module resolution issue, potentially due to an incorrect import path or an older `electron-vite` version.","error":"TypeError: (0, electron_vite_1.defineConfig) is not a function"},{"fix":"Install `@swc/core` by running `npm install -D @swc/core@latest` or `yarn add -D @swc/core@latest`.","cause":"`@swc/core` is a required peer dependency for fast transpilation, and it is missing from your project's `devDependencies`.","error":"Error: @swc/core is a peer dependency and needs to be installed."}],"ecosystem":"npm"}