Hi,
I’ve set up a Worker to consume a Queue and write some data to a KV. I’ve configured the KV in the wrangler.toml file -
name = "worker-name"
main = "src/index.ts"
compatibility_date = "2023-05-09"
usage_model = "bundled"
[env.production]
kv_namespaces = [
{ binding = "SESSIONS_KV", id = "YYYYYYYYYY" }
]
queues.consumers = [
{ queue = "production-queue-name" }
]
[env.staging]
workers.dev = true
kv_namespaces = [
{ binding = "SESSIONS_KV", id = "XXXXXXXX" }
]
queues.consumers = [
{ queue = "staging-queue-name" }
]
When I publish my worker to an environment
wrangler publish --env=staging
I can see that the namespace is available to the worker
Your worker has access to the following bindings:
- KV Namespaces:
- SESSIONS_KV: XXXXXXXX
But when I attempt to use the namespace I get an error message -
✘ [ERROR] ReferenceError: SESSIONS_KV is not defined
Any idea what I’m doing wrong? I’m pretty stumped at this stage.