Skip to content

fix(deploy): resolve worker bundle path from @cloudflare/vite-plugin dist layout#381

Open
AshishKumar4 wants to merge 1 commit into
nightlyfrom
fix/deploy-dist-path-resolution
Open

fix(deploy): resolve worker bundle path from @cloudflare/vite-plugin dist layout#381
AshishKumar4 wants to merge 1 commit into
nightlyfrom
fix/deploy-dist-path-resolution

Conversation

@AshishKumar4
Copy link
Copy Markdown
Collaborator

Summary

The Deploy to Cloudflare button on generated apps fails with:

FileNotFoundError: File not found: /workspace/<instanceId>/dist/index.js

Root cause

worker/services/sandbox/sandboxSdkClient.ts reads a hardcoded /workspace/<id>/dist/index.js, but @cloudflare/vite-plugin emits the worker to dist/<sanitized-name>/index.js and writes a rewritten wrangler.json alongside it. The same file already reads static assets from the modern dist/client/ layout, so the worker-read path was the inconsistent piece.

The hardcoded dist/index.js has been present since the initial OSS release. The user-facing regression surfaced when the R2-hosted templates switched to use @cloudflare/vite-plugin, shifting builds from the flat dist/index.js layout to the plugin's nested dist/<env>/index.js layout.

Verified against a real generated app (lumina-the-beautiful-hello-world):

  • dist/lumina_hello_world_zqneqpyztwbhid_y98ifi/index.js exists
  • dist/lumina_hello_world_zqneqpyztwbhid_y98ifi/wrangler.json exists with main: "index.js", assets.directory: "../client"
  • dist/client/ exists
  • dist/index.js, the path the code tries to read, does not exist

Fix

Resolve both paths from the plugin's own dist/<env>/wrangler.json as the canonical source of truth, falling back to the legacy dist/index.js + dist/client layout for older templates byte-for-byte.

The fix is strictly local to deployToCloudflareWorkers in worker/services/sandbox/sandboxSdkClient.ts. parseWranglerConfig, buildDeploymentConfig, WranglerConfig type, deployer.ts, deploy.ts, cloudflare-api.ts, templates.ts, and the bunx wrangler build step are untouched.

Tests

New unit tests in worker/services/sandbox/resolveBuildArtifacts.test.ts cover:

  1. Modern @cloudflare/vite-plugin layout with ../client assets resolving to sibling dist/client.
  2. Multiple env dirs such as api and web, picking the one matching config.name.
  3. No nested wrangler.json, preserving byte-identical legacy strings.

Verification

  • npm run typecheck passed
  • npm run lint passed
  • npm run test -- worker/services/sandbox/resolveBuildArtifacts.test.ts passed
  • npm run test passed: 216 passed / 1 skipped across 10 test files

…dist layout

Deploy to Cloudflare fails with `FileNotFoundError: /workspace/<id>/dist/index.js`
because the deploy reads a hardcoded `dist/index.js` while @cloudflare/vite-plugin
(pinned ^1.9.4 in templates) emits to `dist/<sanitized-name>/index.js` plus a
rewritten wrangler.json. The same file already uses modern `dist/client/` for
assets, making the worker path the only inconsistent piece.

Resolve both paths from the plugin's own dist/<env>/wrangler.json (canonical
source of truth), falling back to the legacy layout for older templates.

Adds regression tests covering both layouts and the missing-build error.
@ask-bonk
Copy link
Copy Markdown

ask-bonk Bot commented May 13, 2026

ProviderModelNotFoundError

github run

@ask-bonk
Copy link
Copy Markdown

ask-bonk Bot commented May 13, 2026

@AshishKumar4 Bonk workflow failed. Check the logs for details.

View workflow run · To retry, trigger Bonk again.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant