How do you write to Cloudflare KV when developing locally with wrangler dev?

I remember that you could write directly to Cloudflare KV's namespace when running wrangler dev locally.
name = "project_name"
main = "src/index.js"
compatibility_date = "2022-10-06"
type = "webpack"

account_id = "account_id..."
workers_dev = true

kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]

[env.staging]
kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]

[env.production]
kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]
name = "project_name"
main = "src/index.js"
compatibility_date = "2022-10-06"
type = "webpack"

account_id = "account_id..."
workers_dev = true

kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]

[env.staging]
kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]

[env.production]
kv_namespaces = [
{ binding = "namespace_name", id = "id..." }
]
This is what my wrangler.toml looks like. I am currently running by calling wrangler dev. I have logged in with wrangler. It was a while ago since I did this, maybe an update have come or so. Right now it writes to local cache at .wrangler/kv
6 Replies
kian
kian14mo ago
dev in Wrangler 3 runs locally. If you want to access your actual remote namespaces, add --remote to the end of wrangler dev
sten
stenOP14mo ago
Thanks Kian, I had missed that flag. I also forgot to add a preview_id to my kv_namespace. Now it writes to the preview_id when developing locally. Thanks again!
rohnaldino
rohnaldino14mo ago
i still cant access my kv in dashboard when coding i had same error
rohnaldino
rohnaldino14mo ago
No description
rohnaldino
rohnaldino14mo ago
this is what happens when i do that
Adi//
Adi//14mo ago
did you add the same id for both preview and id? ideally that must have worked
Want results from more Discord servers?
Add your server