Build error when using adapter-cloudflare-workers

I am currently trying to deploy a sveltekit website with Cloudflare workers using Cloudflare KV. I've followed this guide https://kit.svelte.dev/docs/adapter-cloudflare-workers I tried building with @sveltejs/adapter-cloudflare:2.3.3 and that works fine, however event.platform.env does not contain Cloudflare KV, even though the .toml file is specified along with the app.d.ts
npmPackages:
@sveltejs/adapter-auto: ^2.0.0 => 2.1.1
@sveltejs/adapter-cloudflare: ^2.3.3 => 2.3.3
@sveltejs/adapter-cloudflare-workers: ^1.2.1 => 1.2.1
@sveltejs/kit: ^1.27.6 => 1.27.6
svelte: ^4.0.5 => 4.2.7
vite: ^4.4.2 => 4.5.0

wrangler.toml file

name = "sveltekit-app"
compatibility_date = "2021-11-12"
account_id = "id"
workers_dev = true
main = "./.cloudflare/worker.js"
site.bucket = "./.cloudflare/public"
build.command = "npm run build"
kv_namespaces = [
{ binding = "KV_1", id = "id", preview_id = "preview" },
{ binding = "KV_2", id = "id", preview_id = "preview" }
]

app.d.ts
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
interface Locals {
user: GithubUser;
KV_1: KVNamespace;
KV_2: KVNamespace;
}
interface Platform {
env?: {
KV_1: KVNamespace;
KV_2: KVNamespace;
};
}
}
declare namespace svelteHTML {
interface HTMLAttributes<T> {
'on:outclick'?: CompositionEventHandler<T>;
}
}
}

export {};
npmPackages:
@sveltejs/adapter-auto: ^2.0.0 => 2.1.1
@sveltejs/adapter-cloudflare: ^2.3.3 => 2.3.3
@sveltejs/adapter-cloudflare-workers: ^1.2.1 => 1.2.1
@sveltejs/kit: ^1.27.6 => 1.27.6
svelte: ^4.0.5 => 4.2.7
vite: ^4.4.2 => 4.5.0

wrangler.toml file

name = "sveltekit-app"
compatibility_date = "2021-11-12"
account_id = "id"
workers_dev = true
main = "./.cloudflare/worker.js"
site.bucket = "./.cloudflare/public"
build.command = "npm run build"
kv_namespaces = [
{ binding = "KV_1", id = "id", preview_id = "preview" },
{ binding = "KV_2", id = "id", preview_id = "preview" }
]

app.d.ts
// See https://kit.svelte.dev/docs/types#app
// for information about these interfaces
declare global {
namespace App {
// interface Error {}
interface Locals {
user: GithubUser;
KV_1: KVNamespace;
KV_2: KVNamespace;
}
interface Platform {
env?: {
KV_1: KVNamespace;
KV_2: KVNamespace;
};
}
}
declare namespace svelteHTML {
interface HTMLAttributes<T> {
'on:outclick'?: CompositionEventHandler<T>;
}
}
}

export {};
Anyone have any clue?
SvelteKit docs
Cloudflare Workers • SvelteKit documentation
2 Replies
sten
sten10mo ago
Just created a minimal reproducible environment https://github.com/socketopp/cf-worker-sveltekit-bug
JohnDotAwesome
JohnDotAwesome10mo ago
Looks like you're using the old Workers Sites setup, not Pages. I'm not sure if you want to use Pages or not but you are posting in the Pages Help, so I suggest following this guide https://kit.svelte.dev/docs/adapter-cloudflare
SvelteKit docs
Cloudflare Pages • SvelteKit documentation
Want results from more Discord servers?
Add your server