Next.js 16 → Tauri 2 Desktop App
Wrap a static-exportable Next.js 16 (App Router) app in a thin Tauri 2 native shell (.exe, .dmg, .AppImage, optional auto-update). Most migration friction comes from Tauri's embedded asset protocol (path/routing resolution), not React.
Guardrails & Scope
- Static-export gate: Confirm the desktop routes work from
output: "export". Keep build-time Server Components and static GET handlers. Request-time rendering, API handlers that need a running Next.js server, or Server Actions require a separate server design. Place desktop hooks inside a client component. Static-export support - Authorization & read-only mode: Read-only assessments stop at blockers and proposed checks without writing files. Migration tasks authorize necessary local edits (
next.config.*,package.json,src-tauri/, desktop frontend boundary, icons,.gitignore, workflows) while preserving unrelated web behavior; do not ask approval before every file write. Signing secrets, OS code signing, and public release actions require explicit user scope. - Release-policy boundary: The bundled workflow builds and verifies a GitHub draft for manual publication (
desktop-app-standarddefaults to direct auto-publication). Preserve the user's requested release policy rather than mixing the two workflows. - Package manager: Commands and
tauri-build.ymlassume Yarn Classic. For npm or pnpm, substitute lockfile install/run commands (npm ci/pnpm install --frozen-lockfile,npm exec --no -- tauri/pnpm tauri) and updatesetup-node'scache:(cache: yarnfails withoutyarn.lock).
Procedure
-
Verify target-compatible stable versions (Tauri 2):
- npm & crates: Check published versions of
@tauri-apps/cli,tauri, and each required plugin. Select compatible stable 2.x releases. In crates.io metadata, use the non-yanked entries inversionsfor the target major. - Actions & Node: Query latest stable Action majors (
gh api repos/actions/checkout/releases/latest --jq .tag_name, plussetup-node,rust-cache,upload-artifact; checktauri-apps/tauri-action@v1README). Pin the current Active LTS Node major from the Node schedule in bothdesktop-build.ymlandtauri-build.yml. Setengines.nodefrom actual Next.js/Tauri CLI floors, not as a copy of the CI major. - (Optional) If
desktop-app-standardis installed, its audit script can supplement version/CI checks, though this migration does not require it.
- npm & crates: Check published versions of
-
Gate static export on Tauri in
next.config.*usingTAURI_BUILD=1(gotcha #1; retain existing reliable gating if present), preserving wrappers likenext-intl:// Keep the NextConfig annotation so wrappers receive the literal "export" type. import type { NextConfig } from "next"; const isTauri = process.env.TAURI_BUILD === "1"; // set by `yarn build:tauri` const nextConfig: NextConfig = { // ...your existing config... ...(isTauri ? { output: "export", trailingSlash: true } : {}), images: { // ...preserve existing image settings... ...(isTauri ? { unoptimized: true } : {}), }, }; export default nextConfig;If the project already wraps its config, retain the existing export, for example
export default withNextIntl(nextConfig)in a next-intl app. Addcross-env(yarn add -D cross-env) and"build:tauri": "cross-env TAURI_BUILD=1 next build"inpackage.jsonsotauri.conf.json'sbeforeBuildCommandsets the flag. -
Scaffold Tauri & icons (JS CLI only; no local Rust needed yet):
yarn add -D @tauri-apps/cli@^2 yarn tauri init --ci --app-name "<app>" --window-title "<Title>" \ --frontend-dist "../out" --dev-url "http://localhost:3000" \ --before-dev-command "yarn dev" --before-build-command "yarn build:tauri" # Master icon must be square (1024x1024 PNG/SVG) to avoid upscaling blur. yarn tauri icon public/logo.pngKeep mobile icon directories if present. Fix
.gitignoreimmediately (gotcha #3) and confirmgit check-ignore src-tauri/tauri.conf.jsonoutputs nothing. -
Configure
src-tauri/: Adapt tauri-files.md (tauri.conf.jsonwith CSP,url,webviewInstallMode,mainBinaryName, optional updater;Cargo.toml;src/lib.rswith single-instance registered first + tray;capabilities/default.json). If shipping without auto-update, apply the full no-updater checklist. -
Integrate the selected frontend features: The client component handles external links. Add the update hook only for apps that support updates (it downloads before asking to install), and add the locale hook only when the app remembers language choices. Mount each hook under the providers it actually uses. For locale-prefixed routes, switch via soft navigation and guard the startup redirect across layout remounts (gotcha #11).
-
Wire single-source versioning & release CI: Add
src-tauri/update-version.cjsand"update-version"script from tauri-files.md, then install both workflow templates and helper scripts per release-workflow.md.- Tag as single version source: On tag push, the template runs
npm pkg set version="${GITHUB_REF_NAME#v}"beforeupdate-versionso installers, embedded version, andtagName: v__VERSION__stay identical (never pointtagNameatgithub.ref_name, gotcha #13). If skipping injection, pushed tag must exactly equalpackage.jsonversion. - Platform signing: Updater signing and Windows/macOS code signing/notarization are separate; report any unsigned/unverified target rather than assuming the template covers it.
- Tag as single version source: On tag push, the template runs
-
Configure updater signing keys (only if updater is enabled): Follow Updater signing keys. Never commit private keys or overwrite an existing key (
-f). -
Verify static export & native build: Run
yarn build:tauriand verifyout/<default-locale>/index.html(orout/index.htmlfor single-locale apps). If Rust and platform libraries are installed locally, build and exercise startup, tray, locale persistence, and updater; otherwise run CI and explicitly report unverified native checks.
Verification & Delivery
Report generated files, checks actually performed, offline/portable constraints, and measured package sizes (a frontend build or CI compile alone does not prove runtime desktop behavior). Hand off only unfinished authorized items (signing credentials, target-device testing, manual draft publication — releases/latest ignores drafts until published). Ensure the release tag commit contains the workflow files.
Gotchas
| # | Pitfall | Fix |
|---|---|---|
| 1 | White screen / extensionless paths fail on Tauri's asset server. | Enable trailingSlash: true under TAURI_BUILD=1 and match tauri.conf.json window url (e.g. /en/) to the default locale. |
| 2 | Runtime locale middleware unavailable in static export. | Gate export via TAURI_BUILD so web keeps its config; verify exported locale directories (Next.js limits). |
| 3 | src-tauri/ ignored by git due to bare src-tauri in .gitignore. |
Replace with src-tauri/target, src-tauri/gen/schemas, src-tauri/*.key; verify with git check-ignore src-tauri/tauri.conf.json. |
| 4 | isTauri() false positives from importing @tauri-apps/api. |
Detect synchronously via window.__TAURI_INTERNALS__ / __TAURI__ / Tauri UA (same bundle ships to web + desktop). |
| 5 | Second launch fails to refocus main window. | Register tauri-plugin-single-instance first in src/lib.rs, gated to #[cfg(desktop)]. |
| 6 | Clients never see update after green CI. | releases/latest ignores drafts/prereleases; publish the verified draft (never delete a published release to rerun — cut a new version). |
| 7 | Private signing key leaked in git history. | Keep src-tauri/*.key gitignored and in GitHub secrets only (.pub is safe to commit); rotate immediately if leaked. |
| 8 | Portable exe treated as self-updating installer. | Raw portable binary still requires WebView2 and lacks guaranteed self-update; catch install failures or disable updater via no-updater checklist. |
| 9 | Wrong OS-language auto-detection. | Preserve the app's language policy. If it uses OS detection, prefer a saved choice, then a supported system locale, then the configured default. |
| 10 | External links navigate in-webview or opener denied. | Intercept external URLs with @tauri-apps/plugin-opener and grant matching URL scopes (opener:default or explicit scoped rules). |
| 11 | Locale switch bounces back on layout remount. | Use soft router.push, keep startup redirect guard in a module-level variable (not useRef), and save preference only in the switcher. |
| 12 | Linux EGL abort or blank AppImage. | Isolate WebKit DMABUF vs bundled libwayland-* conflict first; see Linux diagnosis. |
| 13 | Tag workflow misses CI fixes or mismatches versions. | Tag a commit containing the workflow; inject version from tag before update-version; for multi-app release hubs, preserve the full-SHA source map on reruns. |
