Skip to content

fix(cloudflare): default nodejs_compat for plain Workers, resolve Config/Output in StaticSite build env, relative vite.main - #796

Merged
sam-goodwin merged 5 commits into
mainfrom
claude/alchemy-cloudflare-bugs-4f2db7
Jul 28, 2026
Merged

sam-goodwin merged 5 commits into
mainfrom
claude/alchemy-cloudflare-bugs-4f2db7

Conversation

@sam-goodwin

@sam-goodwin sam-goodwin commented Jul 9, 2026 •

Copy link
Copy Markdown
Member

Fixes for the beta.61 integration bug reports from create-better-t-stack (repros). Every fix was verified by deploying the corresponding repro against a real Cloudflare account.

2. Default nodejs_compat never reached plain Workers

Cloudflare.Worker("w", { main }) (no Effect impl) sets isExternal: true, and getCompatibility only added the default nodejs_compat for Effect-native Workers — so a plain Worker importing node:crypto bundled fine and then failed upload with ScriptModuleNotFound. The default now applies to all Workers, gated on compatibility.date >= 2024-09-23 so a pinned old date doesn't get the legacy v1 mode (which lacks process.getBuiltinModule and fails at script startup). An explicit no_nodejs_compat in compatibility.flags opts out of the default.

Also fixes a latent precreate bug found along the way: the placeholder upload spread ...getCompatibility(news) into metadata, producing date/flags instead of compatibilityDate/compatibilityFlags — the stub deployed with no compatibility settings at all (spreads bypass excess-property checks).

3. StaticSite passed unresolved Config into the build env

serializeEnv JSON.stringified anything that wasn't a string/Redacted, so env: { MY_URL: Config.string("MY_URL") } reached the build subprocess as {"_id":"Config"} (overriding a correct process.env value). It now mirrors the Website.Vite env path:

// strings/Redacted pass through; Config (any runnable Effect) resolves here;
// Outputs resolve at reconcile and the resolved value is serialized the same
// way (Output<object> reaches the subprocess as JSON, not [object Object]);
// null stringifies; binding Effects (WorkerLoader) are dropped
env: yield* serializeEnv(props.env)

A live regression test covers Config, Output<string>, Output<object>, and null env values reaching the build subprocess.

5/6. vite.main — relative paths + docs/API drift

  • ViteOptions.main (documented "Custom Worker Entry") is threaded through Website.Vite and now resolves relative paths against rootDir in both the live and dev providers — the rolldown plugin resolves the worker entry with no importer, so a relative main previously resolved against process.cwd() and broke monorepo deploys.
  • React Router now deploys via the documented option (verified live, SSR serving):
const web = yield* Cloudflare.Website.Vite("web", {
  main: "workers/app.ts", // wraps createRequestHandler (RR's cloudflare template ships this)
});

The plugin-side root causes of issues 4/5 (silent export default {} wrapper, no-importer resolution) are fixed in the companion PR cloudflare-tools#62.

7. memo and monorepo workspace deps

../ include globs already escape cwd end-to-end; this documents the pattern on MemoOptions, StaticSite, and Website.Vite, normalizes absolute glob matches to cwd-relative (they previously broke hashFiles and would have leaked machine paths into the hash), and adds a live test covering rebuild-on-sibling-change.

8. alchemy logs Unauthorized

workers_observability:read is already in the default OAuth scopes (including published beta.61), but tokens keep the scopes they were minted with — an older login fails the telemetry query with a bare Unauthorized. The query now dies with an actionable message pointing at re-running alchemy login.

Docs

Website.Vite JSDoc: SSR examples no longer instruct adding nodejs_compat manually (it's the default), and a React Router example was added.

Issue 1 (Vite SPA "neither assets nor server output") was already fixed on main by #795 — re-verified with the exact repro. Issue 8's poisoned alchemy@2.0.0-pipeline-v2-test npm release needs a maintainer npm deprecate.

🤖 Generated with Claude Code

…ult, StaticSite Config env, vite main resolution

Fixes from the create-better-t-stack integration reports:

- default nodejs_compat now reaches external Workers (plain `export default { fetch }`
  entrypoints set isExternal, which excluded them from the default); gated on
  compatibility date >= 2024-09-23 so pinned old dates don't get the broken v1 mode
- precreate placeholder spread getCompatibility() as date/flags — wrong metadata keys,
  so the stub uploaded with no compatibility date or flags
- StaticSite serializeEnv resolves Config/Effect env values instead of JSON.stringifying
  them into the build subprocess ({"_id":"Config"}); Outputs pass through for the
  engine to resolve
- relative vite.main resolves from rootDir (the rolldown plugin resolves the worker
  entry with no importer, so it resolved against process.cwd())
- memo include globs escaping cwd are documented + absolute matches normalized to
  cwd-relative so machine paths never leak into the hash
- alchemy logs explains the missing workers_observability:read scope on Unauthorized
  instead of surfacing the bare tag

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@alchemy-version-bot

alchemy-version-bot Bot commented Jul 9, 2026 •

Copy link
Copy Markdown
Contributor

Install the packages built from this commit:

alchemy

bun add alchemy@https://pkg.ing/alchemy/55258a1

@alchemy.run/better-auth

bun add @alchemy.run/better-auth@https://pkg.ing/@alchemy.run/better-auth/55258a1

@alchemy.run/pr-package

bun add @alchemy.run/pr-package@https://pkg.ing/@alchemy.run/pr-package/55258a1

- serializeEnv: null no longer throws on the ~alchemy/Kind probe; Output
  values are serialized after resolution via Output.map so Output<object>
  reaches the build subprocess as JSON, not [object Object]
- getCompatibility: an explicit no_nodejs_compat opts out of the default
  nodejs_compat instead of sending Cloudflare a contradictory flag pair
- memo monorepo examples pair ../ include globs with lockfile: true (include
  flips the lockfile default off) and MemoOptions documents the interaction
- add a StaticSite regression test covering Config, Output<string>,
  Output<object>, and null env values reaching the build env (verified it
  fails against the previous serializer)

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
sam-goodwin and others added 2 commits July 28, 2026 15:07
…lare-bugs-4f2db7

# Conflicts:
#	packages/alchemy/src/Cloudflare/Workers/Compatibility.ts
#	packages/alchemy/src/Cloudflare/Workers/LocalWorkerProvider.ts
#	packages/alchemy/src/Cloudflare/Workers/WorkerProvider.ts
#	packages/alchemy/test/Cloudflare/Website/StaticSite.test.ts
Covers the #796 default (Effect-native + external workers), the v2-date
gate, the no_nodejs_compat opt-out, python_workers exclusion, and the
cross-request-promise-resolution behavior.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sam-goodwin sam-goodwin changed the title fix(cloudflare): beta.61 integration bug reports — nodejs_compat default, StaticSite Config env, vite main resolution fix(cloudflare): default nodejs_compat for plain Workers, resolve Config/Output in StaticSite build env, relative vite.main Jul 28, 2026
…lute memo globs

- deploy a plain worker importing node:crypto with no compatibility props —
  the end-to-end repro for the default-nodejs_compat fix
- assert an absolute memo include glob hashes identically to its ../ form;
  this exposed fast-glob silently dropping absolute patterns when mixed
  with relative ones, fixed by rewriting absolute includes to cwd-relative
  in resolveMemoOptions

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@sam-goodwin
sam-goodwin merged commit 96fac36 into main Jul 28, 2026
3 of 4 checks passed
@sam-goodwin
sam-goodwin deleted the claude/alchemy-cloudflare-bugs-4f2db7 branch July 28, 2026 22:59
sam-goodwin added a commit that referenced this pull request Jul 29, 2026
…swarm #972) into url redesign

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
sam-goodwin added a commit that referenced this pull request Jul 29, 2026
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
sam-goodwin added a commit that referenced this pull request Jul 29, 2026
…r-aggregating destroy

Ports into the LocalProvider.make structure:
- make-before-break serveWith (workerd scopes fork from rootScope, closed on
  cutover / closeWorkerd) from #863
- url/urls/domain Attributes + resolveLocalUrls wildcard-host handling from #977
  (local urls no longer carry a trailing slash; tests updated to `${url}/path`)
- ALCHEMY_WORKER_NAME env (#860), viteMain root-relative resolution (#796),
  toRuntimeBinding dev.remote param for send_email (#865)

distilled bumped to main (0.30.2).

Co-authored-by: Cursor <cursoragent@cursor.com>
filipfalcon added a commit to filipfalcon/alchemy-effect that referenced this pull request Sep 14, 2026
`props.vite` was built by a duplicated arm inside the WorkerProvider that
never consulted `ViteOptions.deriveAssets`; `makeViteSource` has existed
since alchemy-run#1086 but was only reached for `props.source`. Dispatch both through
`resolveSource`, and move the self-URL env resolution, the absolute `main`
(alchemy-run#796), and the `base` manifest prefix into the vite source.
filipfalcon added a commit to filipfalcon/alchemy-effect that referenced this pull request Sep 20, 2026
…rive asset routing from its build

Foldkit's `vite build` (`@foldkit/vite-plugin` 0.24+, `ssr.build`) emits
`dist/server/fetch.js`: a Web `fetch` handler with the built shell
embedded, its default export `{ fetch }`. That is a Worker entry, so the
Cloudflare plugin adopts it the way it adopts a TanStack Start server
bundle, and everything the resource did instead goes away: the `main` a
server-rendered app had to name, the Worker that read the shell back out
of the `ASSETS` binding, and the two asset-routing settings that failed
quietly when wrong.

The build also writes `foldkit.build.json` beside the handler, recording
which paths it prerendered, and keeps the unfilled `index.html` out of the
client output, so a server-rendered build needs no routing of its own: a
prerendered route is a file, and every other request, the front page
included, reaches the handler. A build with no manifest is client-only
and gets the single-page-application fallback, the default the other
clouds' Foldkit resources apply. Anything set in `assets` still wins.

`ViteOptions.framework: "foldkit"` names the framework whose build the
vite source knows how to read; a registry maps it to the deriver that
reads the manifest. It is plain data, so it crosses the dev-child
boundary and compares by value in props.

`props.vite` used to be built by a duplicated arm inside the
WorkerProvider that bypassed `makeViteSource`, which has existed since
alchemy-run#1086 but was only reached for `props.source`. Both now dispatch through
`resolveSource`, and the self-URL env resolution, the absolute `main`
(alchemy-run#796), and the `base` manifest prefix move into the vite source.

The SSR example drops its Worker, its `main`, and its asset settings. The
docs describe the delivery shapes and what the build derives for each.
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.

1 participant