Workers KV get throws TypeError: Cannot read properties of undefined (reading 'get')

My wrangler.toml file looks like this:

kv_namespaces = [
  { binding = "BH_API_KEYS", id = "xxx" },
]


In my index.ts file I have:

export interface Env {
    BH_API_KEYS: KVNamespace;
}

...
export default {
    async email(message: any, env: Env, ctx: ExecutionContext) {
            const testApiKey = await env.BH_API_KEYS.get("testId");
...


This code results in the error:

TypeError: Cannot read properties of undefined (reading 'get'


I have verified that my namespace with the given ID exists and is named like
worker-name_namespace-name
.

Why isn't my worker able to access my KV?
Was this page helpful?