Conversation
…udflare#3319) `vinext build --prerender-all` (and `vinext-cloudflare deploy --prerender-all`) renders routes by starting a Node production server against the built output. A Cloudflare target builds a Worker bundle that keeps `cloudflare:*` imports external - only workerd resolves them - so importing that entry under Node died with ERR_UNSUPPORTED_ESM_URL_SCHEME before a single route rendered, even for apps whose prerendered routes never touch a binding. Prerender-purpose servers now register `node:module` loader hooks that resolve every `cloudflare:*` specifier to one inert stub module: the scoped helpers run their callback, `waitUntil` is dropped, and reading `env`/`exports`/`cache`/ `tracing` throws a message naming the cause, so a binding-dependent route fails per-route instead of taking the whole build down. Serving servers are untouched and the deployed bundle still imports the real modules. Tests: - `tests/prerender-workerd-stubs.test.ts` drives the loader hooks and the stub surface directly. - `tests/prerender-cloudflare-bindings.test.ts` runs the real CLI (`vinext build --prerender-all`) against a Cloudflare fixture whose server graph imports `cloudflare:workers`, then asserts the prerendered routes exist and the built bundle still keeps the import external.
@vinext/cloudflare
create-vinext-app
@vinext/types
vinext
@cloudflare/workers-response-store
commit: |
Contributor
Performance benchmarksCompared 0 improved · 0 regressed · 6 within ±1.5%
View detailed results and traces 🟢 improvement · 🔴 regression · ⚫ change below 1.5% · paired base/head |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #3319
Summary
vinext build --prerender-all(andvinext-cloudflare deploy --prerender-all) renders routes by starting a Node production server against the built output. A Cloudflare target builds a Worker bundle that keepscloudflare:*imports external - only workerd resolves them - so importing that entry under Node died withERR_UNSUPPORTED_ESM_URL_SCHEMEbefore a single route rendered, even for apps whose prerendered routes never touch a binding.node:moduleloader hooks that resolve everycloudflare:*specifier to one inert stub module: the scoped helpers run their callback,waitUntilis dropped, and readingenv/exports/cache/tracingthrows a message naming the cause, so a binding-dependent route fails per-route instead of taking the whole build down.purpose: "prerender").Test plan
tests/prerender-workerd-stubs.test.ts- drives the loader hooks and the stub surface directly (resolve/load short-circuit, binding reads throw, probes stay inert, exported names).tests/prerender-cloudflare-bindings.test.ts- runs the real CLI (vinext build --prerender-all) againsttests/fixtures/cf-prerender-bindings, whose server graph importscloudflare:workers; asserts the prerendered routes exist and thatdist/server/index.jsstill keeps the import external.vp run build,vp run check,vp run knip, bash syntax + shard manifest, vitest unit + integration, response-store e2e, create-next-app/create-vinext-app jobs, and the Playwright projects. The only local failures were a build-hash-dependent action-id assertion (fails with and without this change) and e2e specs whose fixed ports were held by another worktree on the same machine.