CF KV functions not working with wrangler dev

Hi, can someone please explain why using
npx wrangler dev
npx wrangler dev
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?
No description
No description
17 Replies
Hello, I’m Allie!
Where are you getting namespace from? It should be a string
Chaika
Chaika8mo ago
would 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
Patternus
PatternusOP8mo ago
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
No description
Patternus
PatternusOP8mo ago
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
Patternus
PatternusOP8mo ago
No description
Hello, I’m Allie!
KV Bindings are defined in your wrangler.toml, not in .dev.vars, which is only for secrets
Patternus
PatternusOP8mo ago
Oh 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
No description
Hello, I’m Allie!
Have you added the bindings in your wrangler.toml?
Chaika
Chaika8mo ago
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
Hello, I’m Allie!
I believe they are using Workers, not Pages
Chaika
Chaika8mo ago
🤔 I thought they mentioned Pages but I might be crazy
Patternus
PatternusOP8mo ago
Yes
No description
Patternus
PatternusOP8mo ago
We are indeed using workers not pages
Hello, I’m Allie!
And you are doing wrangler dev --env=staging?
Patternus
PatternusOP8mo ago
No, I was using wrangler dev without any flags, is that the issue here?
Hello, I’m Allie!
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
Patternus
PatternusOP8mo ago
Alright, as I thought something simple that overlooked. Thank you so much and sorry for bothering
Want results from more Discord servers?
Add your server