Cannot access Cloudflare bindings (env) – always undefined with vite-plugin-cloudflare & nitro-cloudflare-dev #4008
Replies: 2 comments 1 reply
-
exploring this murky area myself. So far it feels like (due the alpha/beta nature of TSR) that there's a sufficiently wide enough spread of misinformation about how to setup TSR with cloudflare. @akawahuynh probs create a minimum reproduction, illustrating how you've configured your app to work with cloud flare. Or at the very least list the following:
import { cloudflare } from "@cloudflare/unenv-preset"; // 1
import { defineConfig } from "@tanstack/react-start/config";
import nitroCloudflareBindings from "nitro-cloudflare-dev"; // 2
import tsConfigPaths from "vite-tsconfig-paths";
const config = defineConfig({
server: {
preset: "cloudflare-pages", // 3
unenv: cloudflare, // 4
modules: [ nitroCloudflareBindings ], // 5
},
vite: {
build: {
sourcemap: true,
},
plugins: [
tsConfigPaths({
projects: ["./tsconfig.json"],
}),
tailwindcss(),
]
},
});
export default config; I got this setup from the cloudflare doc pages: https://developers.cloudflare.com/workers/frameworks/framework-guides/tanstack/ But like I said, I'm not even sure if this is correct (I'm still struggling with mysterious build issues). I feel like either cloudflare or the start examples are out of date. 🤷🏻 |
Beta Was this translation helpful? Give feedback.
-
@airtonix Thanks, i think you are right, your way so far works very well, we should wait for the alpha to be released |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I'm working on integrating Cloudflare D1 with a frontend app using TanStack Start, and trying to run API routes (Cloudflare Pages Functions style) locally with vite-plugin-cloudflare and nitro-cloudflare-dev.
However, env (which should include D1 bindings) is always undefined, both locally and in preview builds.
Guidance on whether this setup is supported
If vite-plugin-cloudflare supports Pages bindings like env.DB
Or if there's a better way to emulate full env bindings locally
Thanks a ton in advance! Appreciate all the work you’re doing in both projects
Beta Was this translation helpful? Give feedback.
All reactions