© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
Cloudflare DevelopersCD
Cloudflare Developers•12mo ago•
10 replies
Jacob

Worker KV Not Binding

I converted a worker from UI to use github/local to push the code. That sync process is working fine to deploy it. The issue is the KV bindings are not holding. If I manually add the KV in the UI then it works, but on next deployment it wipes out the bindings in the UI. My toml:

name = "auth"
account_id = "123"
workers_dev = true
compatibility_date = "2025-02-10"
compatibility_flags = [ "nodejs_compat" ]

main = "./index.js"

[tail_consumers]
service = "tail"

[observability.logs]
enabled = true

kv_namespaces = [
  { binding = "CURATED_EMAIL", id = "abc", preview_id = "abc" }
]
name = "auth"
account_id = "123"
workers_dev = true
compatibility_date = "2025-02-10"
compatibility_flags = [ "nodejs_compat" ]

main = "./index.js"

[tail_consumers]
service = "tail"

[observability.logs]
enabled = true

kv_namespaces = [
  { binding = "CURATED_EMAIL", id = "abc", preview_id = "abc" }
]


I noticed when testing locally with wrangler dev it doesnt pickup these bindings either. I have setup my worker to handle multiple routes:

//index.js
import { registration } from './registration.js';

export default {
    async fetch(request, env) {
        const url = new URL(request.url);

        if (url.pathname === '/registration') {
            return registration(request, env);
        }

        return new Response('Not Found', { status: 404 });
    },
};
//index.js
import { registration } from './registration.js';

export default {
    async fetch(request, env) {
        const url = new URL(request.url);

        if (url.pathname === '/registration') {
            return registration(request, env);
        }

        return new Response('Not Found', { status: 404 });
    },
};

And route:
export async function registration(request, env) {
    // Convert env object to JSON-safe format
    // Changed
    const envBindings = {};
    for (const key in env) {
        envBindings[key] = typeof env[key]; // Show the type of each binding
    }

    console.log('Available Environment Bindings:', JSON.stringify(envBindings, null, 2));

    // Explicitly check if CURATED_EMAIL exists
    if (!env.CURATED_EMAIL) {
        console.error('ERROR: `CURATED_EMAIL` KV binding is missing in `env`!');
    } else {
        console.log('CURATED_EMAIL KV binding exists!');
    }
export async function registration(request, env) {
    // Convert env object to JSON-safe format
    // Changed
    const envBindings = {};
    for (const key in env) {
        envBindings[key] = typeof env[key]; // Show the type of each binding
    }

    console.log('Available Environment Bindings:', JSON.stringify(envBindings, null, 2));

    // Explicitly check if CURATED_EMAIL exists
    if (!env.CURATED_EMAIL) {
        console.error('ERROR: `CURATED_EMAIL` KV binding is missing in `env`!');
    } else {
        console.log('CURATED_EMAIL KV binding exists!');
    }


Everything works fine if I manually add the kv in the UI under worker settings. But I cant get the toml to deploy and actually work. Wipes it out every deployment 😦 Anybody got a clue?
Cloudflare Developers banner
Cloudflare DevelopersJoin
Welcome to the official Cloudflare Developers server. Here you can ask for help and stay updated with the latest news
85,042Members
Resources
Was this page helpful?

Similar Threads

Recent Announcements

Similar Threads

Adding a binding - not visible in worker bindings
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3mo ago
worker not putting into kv?
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
13mo ago
Worker refusing to recognize KV namespace even after binding
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
3y ago
Worker Service Binding not working
Cloudflare DevelopersCDCloudflare Developers / workers-and-pages-help
7mo ago