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

Open
#774 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
56/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Active
Tech stack
zig
Domain
desktop

Research direction

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.

Written by the indexing model from the issue text.

Description

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.

Dominant language
Zig
Stars
7.9k
Forks
335
Avg merge
10h 33m
Merged PRs (30d)
147

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from vercel-labs/native

All issues in vercel-labs/native

Similar issues

More Desktop Dev issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.