CF KV functions not working with wrangler dev
Hi, can someone please explain why using KV functions like getWithMetadata are not working? I added env namespaces using .dev.vars file. Do I need to specify custom bundles to include node modules in the wrangler dev and if so are there any docs for it?
17 Replies
Where are you getting
namespace
from? It should be a stringwould also have to be an already bound kv binding in wrangler.toml
can't just arbitrarily grab namespaces
https://developers.cloudflare.com/kv/reference/kv-bindings/#reference-kv-from-workers
It is string and it is an already bound KV binding, I just specified them in the .dev.vars file as well. Removed actual ID's for safety easures but this is the idea
When logging env[namespace] I get the actual IDs, I suppose there' s something wrong with the binding because I just specified the Ids in env file, do I have to use bindings in the env file? I am a bit confused by it
KV Bindings are defined in your
wrangler.toml
, not in .dev.vars, which is only for secretsOh okay, but then I don't understand why they are not read in wrangler dev. If I remove env file then env[namespace] is an empty object. This is the worker request logic, note that in production it works fine I just can't get it to work using wrangler dev
Probably something simple that I am misunderstanding here
Have you added the bindings in your
wrangler.toml
?In Pages Production it's using the bindings you set in the dashboard, or if you have the pages upload directory set, then it'd be the wrangler.toml
for Pages dev, it's all local, you need to set the bindings in your toml or pass them into pages dev as arguments
I believe they are using Workers, not Pages
🤔 I thought they mentioned Pages but I might be crazy
Yes
We are indeed using workers not pages
And you are doing
wrangler dev --env=staging
?No, I was using wrangler dev without any flags, is that the issue here?
That would probably be it. By default, you aren't using any environment, so if all of your bindings are under an environment, you have none available
Alright, as I thought something simple that overlooked. Thank you so much and sorry for bothering