T
TanStack4w ago
conscious-sapphire

How to fetch data at build time for static deployment on Cloudflare Workers?

I’m using TanStack Start and deploying my site to Cloudflare Workers. I want to fetch some data at build time so it becomes static in the deployed site. From what I can tell, Static Server Functions won’t work in the Cloudflare Workers environment. Is there a recommended way to fetch data during the build step and have it baked into the static output when deploying? Basically: - I want the data to be part of the built site, not fetched at runtime. - I’m deploying to Cloudflare Workers, so I can’t rely on server-side execution. Any advice or best practices for handling this use case in TanStack Start?
4 Replies
sensitive-blue
sensitive-blue4w ago
we are working on making prerendering available for cloudflare. stay tuned
afraid-scarlet
afraid-scarlet2w ago
@Manuel Schiller also not working on Vercel right? Would be nice to have a line in the docs about the types of deployments supported
sensitive-blue
sensitive-blue2w ago
no known issues with vercel here
afraid-scarlet
afraid-scarlet2w ago
Calling this function seems to generate an error:
export const getPricesFromStripe = createServerFn({
method: 'GET',
})
.middleware([staticFunctionMiddleware])
.handler(async (): Promise<StripeProductWithPrices[]> => {
const stripe = new Stripe(envServer.STRIPE_SECRET_KEY, {
apiVersion: '2025-10-29.clover',
})

const { data: allproducts } = await stripe.products.list({
active: true,
limit: 100,
})

const productPromises = allproducts.map(async (product) => {
// Fetch all prices for this product
const { data: prices } = await stripe.prices.list({
product: product.id,
active: true,
})

return {
id: product.id,
slug: product.metadata.slug,
name: product.name,
prices,
}
})

return await Promise.all(productPromises)
})
export const getPricesFromStripe = createServerFn({
method: 'GET',
})
.middleware([staticFunctionMiddleware])
.handler(async (): Promise<StripeProductWithPrices[]> => {
const stripe = new Stripe(envServer.STRIPE_SECRET_KEY, {
apiVersion: '2025-10-29.clover',
})

const { data: allproducts } = await stripe.products.list({
active: true,
limit: 100,
})

const productPromises = allproducts.map(async (product) => {
// Fetch all prices for this product
const { data: prices } = await stripe.prices.list({
product: product.id,
active: true,
})

return {
id: product.id,
slug: product.metadata.slug,
name: product.name,
prices,
}
})

return await Promise.all(productPromises)
})
When deploying on vercel. forntend console
Error: ENOENT: no such file or directory, mkdir 'dist'
at purchase:2:1307
at purchase:2:2055
Error: ENOENT: no such file or directory, mkdir 'dist'
at purchase:2:1307
at purchase:2:2055
this is where it is called:
export const Route = createFileRoute('/purchase')({
loader: async () => {
const prices = await getAddonPrices()
return { prices }
},
component: RouteComponent,
})
export const Route = createFileRoute('/purchase')({
loader: async () => {
const prices = await getAddonPrices()
return { prices }
},
component: RouteComponent,
})

Did you find this page helpful?