Access bindings in dev
I'm following this tutorial:
https://developers.cloudflare.com/pages/framework-guides/deploy-a-svelte-site/
And I've also tried the Qwik tutorial. I'm running the dev server using
npm run pages:dev
so using wrangler. In the case of Qwik, in the console I can see the message:
But the context is not provided to the request handler. In the case of Svelte,
The SvelteKit docs do say "platform.env is only available in the final build and not in dev mode." But I'm not sure how anyone is doing development without the bindings. Just build every time I want to test?
Am I missing something? Anyone have any suggestions or workaround?Deploy a Svelte site · Cloudflare Pages docs
Svelte is an increasingly popular, open-source framework for building user interfaces and web applications. Unlike most frameworks, Svelte is …
SvelteKit docs
Cloudflare Pages • SvelteKit documentation
4 Replies
Can anyone just confirm if I'm right in thinking that bindings are not available when running dev?
bump
Could it be related to this: https://github.com/cloudflare/workers-sdk/issues/5315#issuecomment-2081407344
GitHub
Do not deprecate wrangler's proxy feature, e.g. `wrangler pages dev...
Edit: I edited the issue title since this thread has been evolved about how to inject CF env vars into a hot reloading dev server, the actual issue is further down: #5315 (comment) Which Cloudflare...
Bindings should work in dev out of the box. In late January (not sure of the specific version but can look it up if needed) Svelte changed the Cloudflare adapter to use
getBindingsProxy
which will automatically emulate any bindings defined in your wrangler.toml
when running vite dev
in a svelte project
for reference, here's the PR: https://github.com/sveltejs/kit/pull/11732/files#diff-55dd33c380314b0ebda94b3dea7190b010f2fb9824c7303ecf7d994d7df04ac1R147
I just tried this on a fresh project with npm create cloudflare@latest -- --framework svelte
and it seems to be working