emilycheyne
emilycheyne
CDCloudflare Developers
Created by emilycheyne on 3/6/2024 in #workers-help
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" },
]
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");
...
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'
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
worker-name_namespace-name
. Why isn't my worker able to access my KV?
5 replies