Skip to content

fix(cloudflare-rolldown-plugin): inline wasm/bin/text content in dev SSR#847

Closed
Cyberistic wants to merge 1 commit into
alchemy-run:mainfrom
Cyberistic:fix/cloudflare-rolldown-plugin-ssr-load
Closed

fix(cloudflare-rolldown-plugin): inline wasm/bin/text content in dev SSR#847
Cyberistic wants to merge 1 commit into
alchemy-run:mainfrom
Cyberistic:fix/cloudflare-rolldown-plugin-ssr-load

Conversation

@Cyberistic

@Cyberistic Cyberistic commented Jul 16, 2026

Copy link
Copy Markdown

PR CLOSED AND MOVED TO: alchemy-run/cloudflare-tools#67

@Cyberistic
Cyberistic marked this pull request as draft July 16, 2026 21:21
The `additional-modules` plugin rewrites `import 'foo.wasm'` (and .bin,
.txt, .html, .sql) to a virtual `__CLOUDFLARE_MODULE__CompiledWasm__/<abs>
__CLOUDFLARE_MODULE__` URL so the bundler can inline the file's content
as an asset at build time.

In dev (no `renderChunk`), Vite's Node-side SSR module runner still
resolves that virtual ID and then tries to load it. The 'file' portion
is just a marker — vite's `transformRequest` runs, finds no real file
on disk, and throws `Failed to load url __CLOUDFLARE_MODULE__...`.

Fix: add a `load` hook that matches the virtual id, reads the
.on-disk .wasm / .bin / .txt file here in the plugin (Vite Node main
process), and inlines the bytes as a base64 string literal in the
returned module source.

Why base64: Vite evaluates the returned source inside
`new AsyncFunction(...)`, where top-level `import` statements are
illegal. The returned source has no imports — it builds the buffer
from the inlined string with `Buffer.from(__b64, 'base64')`.

Why CompiledWasm / Text / Data each get their own branch:
`CompiledWasm` and `Data` should produce binary buffers;
`Text` is utf-8 text. Each branch emits a default export of the
correct shape for its consumer.
@Cyberistic
Cyberistic force-pushed the fix/cloudflare-rolldown-plugin-ssr-load branch from 6d7f3c4 to 97c1893 Compare July 16, 2026 21:21
@Cyberistic Cyberistic closed this Jul 16, 2026
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.

2 participants