Skip to content

tanstack-start on cloudfare - env not #912

@chaotic-justice

Description

@chaotic-justice

tanstack-start-cloudfare-template

followed this template above.

however when declaring env at the beginning of __root.tsx, then using it to access GT secrets, it throws error
"[vite] Internal server error: Failed to resolve import "cloudflare:workers" from "src/routes/__root.tsx". Does the file exist?"

function RootComponent() {
	return (
		<GTProvider
			{...gtConfig}
			projectId={env.GT_PROJECT_ID}
			devApiKey={env.GT_API_KEY}
			loadTranslations={loadTranslations}
			dictionary={dictionary}
		>
			<RootDocument>
				<Outlet />
			</RootDocument>
		</GTProvider>
	);
}

function RootDocument({ children }: { children: React.ReactNode }) {
	return (
		<html>
			<head>
				<HeadContent />
			</head>
			<body className="min-h-screen p-4 font-sans antialiased bg-background md:p-8">
				<Header />
				<main className="flex-1">{children}</main>
				<Toaster richColors />
				<TanStackRouterDevtools position="bottom-right" />
				<ReactQueryDevtools buttonPosition="bottom-left" />
				<Scripts />
			</body>
		</html>
	);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions