How to use remote kv worker while running in local environment?

According to the docs, I have added the required flags
wrangler dev ./build/index.js --env production --experimental-local=true --experimental-local-remote-kv=true
wrangler dev ./build/index.js --env production --experimental-local=true --experimental-local-remote-kv=true
Even after then it is still throwing this error:
[ERROR] In development, you should use a separate kv namespace than the one you'd use in production. Please create a new kv namespace with "wrangler kv:namespace create <name> --preview" and add its id as preview_id to the kv_namespace "POSTS" in your wrangler.toml
[ERROR] In development, you should use a separate kv namespace than the one you'd use in production. Please create a new kv namespace with "wrangler kv:namespace create <name> --preview" and add its id as preview_id to the kv_namespace "POSTS" in your wrangler.toml
5 Replies
Hello, I’m Allie!
In your wrangler.toml, instead of
kv_namespaces = [
{ binding = "<MY_NAMESPACE>", id = "<KV_ID>" }
]
kv_namespaces = [
{ binding = "<MY_NAMESPACE>", id = "<KV_ID>" }
]
, put
kv_namespaces = [
{ binding = "<MY_NAMESPACE>", id = "<KV_ID>", preview_id = "<KV_ID_AGAIN>"}
]
kv_namespaces = [
{ binding = "<MY_NAMESPACE>", id = "<KV_ID>", preview_id = "<KV_ID_AGAIN>"}
]
, which should stop it complaining.
Yashu
YashuOP2y ago
But I want to write (modify) the data of production kv store from local. Using preview_id, will create a separate kv store.
Hello, I’m Allie!
Not if you set the preview_id to the same ID as your production ID.
Yashu
YashuOP2y ago
ahhh! didn't thought of that.
Hello, I’m Allie!
That's basically a way of consenting saying "Yeah, I know I'm running on production data. I'm willing to take that risk" Since you have to manually do it, it's your responsibility if you break something.
Want results from more Discord servers?
Add your server