Skip to content

fix(deploy): emit additional modules and use Worker conditions in framework Worker bundles - #538

Closed
Pleasurecruise wants to merge 1 commit into
voidzero-dev:mainfrom
Pleasurecruise:fix/framework-worker-modules
Closed

Pleasurecruise wants to merge 1 commit into
voidzero-dev:mainfrom
Pleasurecruise:fix/framework-worker-modules

Conversation

@Pleasurecruise

Copy link
Copy Markdown

Fixes #535.

prepareBundledBuildOutput re-bundles framework Worker output with a plain Vite lib build. Compared with @cloudflare/vite-plugin, that build has two gaps:

  • .wasm, .bin, .txt, .html and .sql imports are bundled as JavaScript. A plugin now applies the Cloudflare Vite plugin's additional module rules: it resolves # subpath imports, keeps matches external, and emits each file in renderChunk with a chunk-relative path. copyBundle then uploads them with their existing module types. The Cloudflare plugin does not export this logic, so it is reimplemented here.
  • Dependencies resolve with browser conditions, so a package that exports both workerd and browser builds gets the browser one. For example, decode-named-character-reference (used by micromark) then calls document.createElement at module load, and the deployed Worker fails with ReferenceError: document is not defined. The build now uses WORKER_CONDITIONS, moved from wrapper.ts to its own module so cf-build-output.ts still imports Vite lazily.

Both changes apply to every bundle built by prepareBundledBuildOutput, including the static Worker.

Test

  • New unit tests: wasm-bindgen-style and plain Wasm, text and data imports, a # subpath import and a dynamic import become wasm/text/data modules and pass cf dry-run; a dependency with workerd and browser exports resolves to its workerd build. Each fails without its fix.
  • vp test run for cf-build-output.test.ts, wrapper.test.ts, scheduled-dispatch.test.ts and sveltekit-worker-build.test.ts, and vp run --filter ./packages/void typecheck pass.
  • Verified against a real SvelteKit app using @resvg/resvg-wasm and micromark: the deployed Worker serves SSR pages.

@Pleasurecruise
Pleasurecruise deleted the fix/framework-worker-modules branch October 21, 2026 22:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Native deploy fails when a framework Worker imports Wasm, text or data modules

1 participant