electron-next is a utility package designed to seamlessly integrate Next.js into Electron applications, primarily for powering the renderer process. It handles both development and production workflows, ensuring that Next.js bundles are correctly served within Electron's file:// protocol environment in production, and managing the development server in development. The current stable version is 3.1.5. Based on recent activity, the package has a moderate release cadence, focusing on patches, dependency upgrades, and minor features rather than major breaking changes. Its key differentiator is simplifying the often-complex setup of using a modern web framework like Next.js within a desktop application shell, abstracting away much of the configuration required for renderer process bundling and serving.
npm install electron-nextVerified import paths — ran on the pinned version, not inferred.
This code demonstrates the basic setup for an Electron application using electron-next. It initializes the Next.js renderer, creates an Electron window, and correctly loads the Next.js application based on the `NODE_ENV` (development server or production build).
Ensure `electron` and `next` are listed in your project's `package.json` dependencies and installed (e.g., `npm install electron next` or `yarn add electron next`).
Pass a specific, unused port number as the second argument to `prepareRenderer(path, myCustomPort)` or set `process.env.ELECTRON_NEXT_PORT`.
Upgrade to `electron-next@3.1.1` or newer to ensure full compatibility and stability on Windows operating systems.
Upgrade to `electron-next@3.1.2` or newer. If stuck on an older version, avoid spaces in your application's directory or name.
Run `npm install electron-next` or `yarn add electron-next` in your project's root directory.
Specify an alternative port for `prepareRenderer` (e.g., `await prepareRenderer(path, 8001)`) or ensure no other applications are using port 8000.
Ensure you have run `next build && next export` in your Next.js renderer directory and that the `path` argument points to the correct location of your Next.js application.
For Electron's main process, `require()` is standard. For renderer processes, if `nodeIntegration` is false and `contextIsolation` is true, use a preload script and `contextBridge` to expose Node.js APIs or switch to ESM imports if your project is configured for it.