Windows packaged app shows only `Asset not found`: bundled frontend assets resolve against the process cwd, not the artifact

Aperta
#774 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
56/100
Tipo di issue
Bug
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
zig
Ambito
desktop

Direzione di ricerca

Read src/platform/windows/webview2_host.cpp around assetFilePath and compare its asset resolution with the root_path handling described for macOS and Linux in platform/macos/root.zig and platform/linux/root.zig. Then trace how the packaged artifact sets the asset root in src/tooling/package.zig. Done means a Windows package finds and renders its bundled frontend when launched from bin/, with the existing package layout intact.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

Environment

  • @native-sdk/cli 0.11.1, Windows 11, Zig 0.16.0
  • app.json has "frontend": { "dist": "frontend/dist", "entry": "index.html", "spa_fallback": true }, "capabilities": ["webview"], "web_engine": "system"

Steps

native build shelltest --yes
native package --target windows --manifest app.json --assets frontend/dist \
  --output zig-out/package/win --binary zig-out/bin/shelltest.exe \
  --web-engine system --web-layer include

Packaging reports success:

info[package.created]: created windows artifact at zig-out/package/win
  web layer: webview2 (declared: .frontend)
  subsystem: gui

The artifact is laid out as:

win/
  bin/shelltest.exe
  bin/WebView2Loader.dll
  resources/frontend/dist/index.html
  resources/frontend/dist/asset-manifest.zon

Expected — per /docs/packaging: "Production packages serve these through zero://app/, so paths like /assets/app.js work without file:// URLs", and native build + native package is described as "the complete path from source to distributable". Double-clicking bin/shelltest.exe should render index.html.

Actual — the window opens with a single line of body text:

Asset not found

That string comes from the Windows scheme handler's 404 branch
(src/platform/windows/webview2_host.cpp:5244,
return textWebResourceResponse(environment, 404, L"Not Found", "Asset not found")),
i.e. the file lookup failed rather than the document being empty. There is no console
error, no dialog, and no hint about which path was tried. Note that the runtime log line
webview.load ... kind="assets" bytes=10 is printed on both the working and the
failing run (it reports the asset id length, not the payload), so it is not a signal.

Why

The packaged assets live at <output>/resources/<frontend.dist>:

// src/tooling/package.zig:503,765
const assets_output = try assetOutputPath(allocator, options.output_path, "resources", options);
// -> <output>/resources/<frontend.dist>

But on Windows the webview resolves an asset URL by concatenating the manifest's
dist string onto the process working directory:

// src/platform/windows/webview2_host.cpp:1128
static std::wstring assetFilePath(const ChildWebView &webview, const std::string &relative) {
    std::string path = webview.asset_root.empty() ? std::string(".") : webview.asset_root;
    ...
    path += native_relative;   // "frontend/dist" + relative, relative to cwd

asset_root is the literal frontend/dist baked in by
frontend.productionSource(.{ .dist = "frontend/dist" }) — it is never rebased onto the
artifact directory. On macOS and Linux the platform layer receives root_path
(platform/macos/root.zig:1388, platform/linux/root.zig:770) and is described in the
docs as resolving "against Contents/Resources", so the package layout and the resolver
agree there. On Windows they do not: when the app is launched by double-click, the cwd is
bin/, so <cwd>/frontend/dist/index.html does not exist.

Controlled experiment (same binary, no rebuild)

setup cwd result
as packaged (resources/frontend/dist) bin/ body text Asset not found (404 from the scheme handler)
resources/frontend/dist copied to bin/frontend/dist bin/ renders normally

Same binary, same working directory, same command — only the asset location changed.

Nothing else changed, so the missing piece is the app-relative resolution.

Note on the obvious workaround

Computing an absolute asset_root from the executable directory in Zig is not a one-liner
on 0.16: std.fs.selfExePath* no longer exists (grep -rn selfExe zig/lib/std returns
nothing; path handling moved to std.Io.Dir). Users have no supported way to fix this
from application code, which is why the cwd-relative lookup matters.

Expected fix

Resolve asset_root against the artifact/executable directory on Windows (mirroring
macOS/Linux), so the default build + package output works when double-clicked.

Lingua principale
Zig
Stelle
7.9k
Fork
335
Merge medio
10h 33m
PR unite (30g)
147

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel-labs/native

Tutte le issue di vercel-labs/native

Issue simili

Altre issue su Desktop Dev

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.